C PROGRAMMING Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

C PROGRAMMING

WHAT IS PROGRAMMING?
Programming is the process of creating instructions for a computer to execute. It involves writing code in
a specific programming language to solve problems, automate tasks, or develop software applications.
Through programming, developers can manipulate data, control hardware, and build complex systems
that power the digital world.

C LANGUAGE :
C is a high-level, general-purpose programming language initially developed by Dennis Ritchie at Bell Labs
in the early 1970s. It is one of the most influential programming languages and has greatly influenced
many other programming languages, including C++, Java, Python, and many more.

FEATURES OF C LANGUAGE :
1. Simplicity: C is designed to be simple and straightforward. It has a clear and concise syntax, making
it easy to read and write code.

2. Portability: C programs can run on different types of computers with minimal changes. This means
that once you write a C program, it can work on various machines without much hassle.

3. Modularity: C allows you to break down your program into smaller, manageable parts called
functions. These functions can be reused in different parts of your program, making it easier to
organize and maintain your code.

4. Efficiency: C is known for its efficiency in terms of both execution speed and memory usage. It
allows you to write programs that run quickly and use system resources effectively.

5. Flexibility: C provides a wide range of operators, data types, and control structures, giving you the
flexibility to express your ideas and solve problems in different ways.

6. Low-Level Features: C gives you direct control over the computer's hardware, allowing you to
manipulate memory and perform low-level operations when needed.

7. Extensibility: C can be easily extended through libraries and other languages like assembly
language. This allows you to add new features to your programs or optimize performance as
needed.
SYNTAX OF C PROGRAMMING :
1. Preprocessor Directives (Optional):

• Lines starting with # symbol.

• Instructions for the compiler before actual compilation (e.g., including header files).

• Common example: #include <stdio.h> which includes the standard input/output library.

2. Main Function:

• Every C program requires a main function where program execution begins.

• Follows the format:

int main()

// Code to be executed

return 0;

• int specifies the return type (often integer).

• Curly braces {} enclose the code to be executed.

• return 0; indicates successful program termination.

3. Variables:

• Variables store data during program execution.

• Declaration specifies data type and variable name (e.g. int age;).

• Common data types include int (integers), float (decimals), char (single characters), etc.

4. Statements:

• Instructions that the program performs.

• End with a semicolon ;


VARIABLES IN C :

Define :
1) It is a name of storage space which is used to store data.
2) It’s value is changeable.
3) It always contains last value stored to it.
4) It’s always declared with data types.

Variable Declaration :
Variable declaration in C involves specifying the data type and name of the variable. It allocates
memory for the variable. Optionally, you can also initialize the variable with an initial value. Here's a
brief example:

int age; // Declaration of an integer variable named 'age'

float height; // Declaration of a floating-point variable named 'height'

Variables are typically declared at the beginning of a function or block in C programming.

Variable Initialization :
Variable initialization in C involves assigning an initial value to a variable at the time of declaration.
This sets the variable to a specific value from the start.

• data_type: Specifies the type of data that the variable can hold, such as int, float, char, etc.

• variable_name: The name chosen by the programmer to identify the variable. It follows the
rules for variable naming conventions in C.

• initial_value: The value assigned to the variable at the time of declaration.

example :-

int age = 25; // Initializing an integer variable 'age' with an initial value of 25

float height = 5.9; // Initializing a floating-point variable 'height' with an initial value of 5.9

char grade = 'A'; // Initializing a character variable 'grade' with an initial value of 'A'
You can also initialize multiple variables of the same data type on the same line:

int x = 10, y = 20, z = 30; // initialize variable in single line.

Rules to declare a variable :-

• The first letter of a variable should be alphabet or underscore( _ ).


• the first letter of variable should not be digit.
• After first character it may be combination of alphabets and digits.
• Blank spaces are not allowed in variable name.
CONSTANTS IN C :

Define :

• An element of program whose value can not be changed at a time of execution of


program is called constant.
• It’s also called as literals.
• It may be int, float and character data type.

Use of constants in program :-


There are two way of using constants in the C program :
1. Using const
2. Using #define

Example :-
int roll = 201;
float marks = 85.6;
char grade = ‘A’;

Here 201 is a integer constant,


85.6 is a float constant,
‘A’ is character constant.
Keyword in C Language

Define :

• The word has a predefined meaning is called keywords.


• It’s functionality is also predefined.
• It can not be used as an identifier.
• There are 32 keywords are used in C.

32 Keywords are given below :-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy