1 of 20

WELCOME TO C PROGRAM

2 of 20

  •  The data type is a collection of data with values having fixed values, meaning as well as its characteristics.

Ex:-125,hello etc…

DATA TYPES

INT

FLOAT

DOUBLE

CHAR

VOID

DATA TYPE

3 of 20

INT:-

The integer data type in C is used to store the whole numbers without decimal values. Octal values, hexadecimal values, and decimal values can be stored in int data type in C.

Range:  -2,147,483,648 to 2,147,483,647

  • Size: 2 bytes or 4 bytes
  • Format Specifier: %d

FLOAT:-

In C programming float data type is used to store floating-point values. Float in C is used to store decimal and exponential values .

  • Range: 1.2E-38 to 3.4E+38
  • Size: 4 bytes
  • Format Specifier: %f

DOUBLE:-

A Double data type in C is used to store decimal numbers (numbers with floating point values) with double precision. It can easily accommodate about 16 to 17 digits after or before a decimal point.

  • Range: 1.7E-308 to 1.7E+308
  • Size: 8 bytes
  • Format Specifier: %lf

4 of 20

CHAR:-

Character data type allows its variable to store only a single character. The storage size of the character is 1.

  • Range: (-128 to 127) or (0 to 255)
  • Size: 1 byte
  • Format Specifier: %c

VOID:-

The void data type in C is used to specify that no value is present. It does not provide a result value to its caller. It has no values and no operations. It is used to represent nothing. Void is used in multiple ways as function return type, function arguments as void, and pointers to void.

5 of 20

Variables

variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times. It is a way to represent memory location through symbol so that it can be easily identified.

SYNTAX:-

type variable_list;  

Ex:-

int c; // c is a integer variable 

char t; // t is a character variable 

float f; // f is a float variable  

Rules for defining variables

  • A variable can have alphabets, digits, and underscore.
  • A variable name can start with the alphabet, and underscore only. It can't start with a digit.
  • No whitespace is allowed within the variable name.
  • A variable name must not be any reserved word or keyword, e.g. int, float, etc.

6 of 20

An operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise, etc.

There are following types of operators to perform different types of operations in C language.

  • Arithmetic Operators:- used to perform to arithmetic operations such as addition, subtraction etc... Ex:-+,-,*,/,%
  • Relational Operators:- used to create a relationship and compare the values of two operands. Ex.>,<,>=,<=,==,!= etc..
  • Shift Operators:-used to shift the binary bits either in left or right direction. Ex:-<<,>>
  • Logical Operators:-used to perform logical operations. These are logical AND, logical OR, logical NOT. Ex:-&&,||,!
  • Bitwise Operators:-these operators are used to make bit operations. EX:-&,|,!,^,~ etc..
  • Ternary or Conditional Operators:-The behavior of conditional operator is similar to the IF-ELSE statement. It is represented by two symbols, i.e., ’?’ and ‘:’.
  • Assignment Operator:-Used to assign the value, variable and function to another variable. Ex:=,+=,-=,/=,*=, etc….

Operators

7 of 20

Control statements

Control statements are used to execute certain block of code based on the condition.

Control statements are divided into three types.

  • Selection statements
  • Iterative statements
  • Jump statements

Selection statements:-

The selection statement means the statements are executed depends – upon a condition.

Selection statements

SIMPLE IF

IF-ELSE

IF ELSE-IF

NESTED-IF

8 of 20

SIMPLE-IF:

 if expression is true (nonzero) statement is executed. If expression is false, statement is ignored.

SYNTAX:-

If(condition)

{

//statement 1

}

Statement 2..

IF-ELSE:-

executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed

SYNTAX:-

If(condition)

{

Statement1

}

Else

{

Statement 2

}

Statement 3………

9 of 20

IF ELSE-IF:-

used to test many conditions .if condition fails condition 2 is checked if it fails then condition 3 and so on…if one condition is true then statement related to that condition gets executed otherwise else block gets executed.

SYNTAX:-

If(condition 1)

{

//statement1

}

Else if(condition 2)

{

//statement2

}

Else if(condition 3)

{

//statement3

}

Else

{

Statement n;

}

………….

10 of 20

NESTED IF:-

An IF condition within in another condition is called NESTED-IF.

SYNTAX:--

If(condtion1)

{

If(condition 2)

{

Statement 2

}

Statement 1

}

SWITCH CASE:-

It is same as if else if ladder. It will all the cases if one of the case is true then body or statements of that case will be executed otherwise default block will be executed…

SYNTAX:-

switch(condition)

{

Case 1 : statement 1;break;

Case 2 : statement 2;break;

Case 3 : statement 3;break;

default :statement;

}

11 of 20

Iterative statements:

Loop is used to execute the block of code several times according to the condition given in the loop. It means it executes the same code multiple times so it saves code and also helps to traverse the elements of an array.

1. while Loop –

While loop execute the code until condition is false. It is a pre conditional loop.

SYNTAX

While(condition)

{

Code;

}

2. for Loop –

for loop execute the code until condition is false. It is a pre conditional loop. It takes 3 arguments.

SYNTAX

for(initialization;condition;increment/decrement)

{

Code;

}

12 of 20

3.do while

do while loop execute the code until condition is false. It is a post conditional loop. It will execute the code at least one time before the condition false.

SYNTAX

do

{

Code;

}while(condition);

JUMP STATEMENTS:

These are used to move the control to a specified location.

1.break:used to stop or break the loop immediately when a condition satisfied.

SYNTAX: break;

2.continue:used to stop or break one iteration when a condition satisfied.

SYNTAX: continue;

3.Goto:used to move a specific location when a condition is satisfied.

SYNTAX: lable

……..

goto lable;

13 of 20

Functions

we can divide a large program into the basic building blocks known as function. The function contains the set of programming statements enclosed by {}. A function can be called multiple times to provide reusability and modularity to the C program. In other words, we can say that the collection of functions creates a program. 

Note:

in order to use function we have to declare,call and define the functions.

  • There are two types of functions
  • User defined:
  • System defined

Types of functions

function without arguments and without return value

function without arguments and with return value

function with arguments and without return value

function with arguments and with return value

14 of 20

RECURSIVE FUNCTION:

Any function which calls itself is called recursive function, and such function calls are called recursive calls. Recursion involves several numbers of recursive calls. However, it is important to impose a termination condition of recursion. Recursion code is shorter than iterative code however it is difficult to understand.

CALL BY REFERENCE:

  • In call by reference, the address of the variable is passed into the function call as the actual parameter.
  • The value of the actual parameters can be modified by changing the formal parameters since the address of the actual parameters is passed.

SYNTAX: function(&variable1,&variable2)

CALL BY VALUE:

In call by value method, the value of the actual parameters is copied into the formal parameters. In other words, we can say that the value of the variable is used in the function call in the call by value method.

SYNTAX: function(variable1,variable2)

15 of 20

Pointers

The pointer in C language is a variable which stores the address of another variable. This variable can be of type int, char, array, function, or any other pointer. The size of the pointer depends on the architecture. However, in 32-bit architecture the size of a pointer is 2 byte.

Declaration:

  1. int *a;//pointer to int  
  2. char *c;//pointer to char  

Initialization

a=&variable;

POINTER ARITHMETICS

We can perform arithmetic operations on the pointers like addition, subtraction, etc. However, as we know that pointer contains the address, the result of an arithmetic operation performed on the pointer will also be a pointer if the other operand is of type integer. 

SYNTAX

new_address= current_address + i * size_of(data type)  

16 of 20

Storage classes

Storage Classes are used to describe the features of a variable/function. These features basically include the scope, visibility and life-time which help us to trace the existence of a particular variable during the runtime of a program.

17 of 20

Arrays

An array is defined as the collection of similar type of data items stored at contiguous memory locations. Arrays are the derived data type in C programming language which can store the primitive type of data such as int, char, double, float, etc. It also has the capability to store the collection of derived data types, such as pointers, structure, etc. The array is the simplest data structure where each data element can be randomly accessed by using its index number.

ARRAY TYPES

1-D

2-D

DECLARATION

data_type  array_name[array_size];  

INITIALIZATION

int marks[5]; 

DECLARATION

data_type  array_name[array_size] [array_size];  

INITIALIZATION

int marks[5][5]; 

18 of 20

Function pointer

As we know that we can create a pointer of any data type such as int, char, float, we can also create a pointer pointing to a function. The code of a function always resides in memory, which means that the function has some address. We can get the address of memory by using the function pointer.

Declaration of a function pointer

SYNTAX

return type (*ptr_name)(type1, type2…);  

EX:

int (*ip) (int);  

19 of 20

Array of pointers

We know variable and collection of variables or values known as Array.

In the same way pointer can also used to store collection of addresses which is known as array of pointers.

Declaration

Datatype *pointer_name[size];

Initialization

Int *p[5];

20 of 20

Thank you