C Programming Language Tutorial
C Programming Language Tutorial
LANGUAGE
TUTORIAL
WHAT IS C LANGUAGE:-
Developed by Dennis Ritchie for creating system
applications that directly interact with the
hardware devices such as drivers, kernels, etc.
It is considered as the base for other programming
languages, that is why it is known as mother
language.
It can be defined by the following ways:
Mother language
System programming language
Procedure-oriented programming language
Structured programming language
Mid-level programming language
HISTORY OF C PROGRAMMING
FEATURES OF C LANGUAGE:-
#include <stdio.h>
#include <conio.h>
void main(){
printf(“Vedisoft”);
getch();
}
DESCRIBE THE C PROGRAM :-
if(expression){
//code to be execute
}
IF ELSE STATEMENT:-
The if-else statement is used to execute the
code if condition is true or false.
Syntax:
if(expression){
//code to be executed if condition is true
}else{
//code to be executed if condition is false
}
IF ELSE-IF LADDER STATEMENT:-
Syntax:
if(condition1){
//code to be executed if condition1 is true
}else if(condition2){
//code to be executed if condition2 is true
}
else if(condition3){
//code to be executed if condition3 is true
}
...
else{
//code to be executed if all the conditions are false
}
C SWITCH STATEMENT:-
Syntax:
switch(expression){
case value1:
//code to be executed;
break; //optional
case value2:
//code to be executed;
break; //optional
......
default:
code to be executed if all cases are not matched;
}
LOOPS IN C LANGUAGE:-
Loops are used to execute a block of code or
a part of program of the program several
times.
Types of loops in C language:-
There are 3 types of loops in c language.
1) do while
2) while
3) for
DO-WHILE LOOP IN C:-
It is better if you have to execute the code
at least once.
Syntax:-
do{
//code to be executed
}while(condition);
WHILE LOOP IN C LANGUAGE:-
It is better if number of iteration is not
known by the user.
Syntax:-
while(condition){
//code to be executed
}
FOR LOOP IN C LANGUAGE:-
It is good if number of iteration is known by
the user.
Syntax:-
for(initialization;condition;incr/decr){
//code to be executed
}
C BREAK STATEMENT:-
it is used to break the execution of loop
(while, do while and for) and switch case.
Syntax:-
jump-statement;
break;
CONTINUE STATEMENT IN C LANGUAGE:-
it is used to continue the execution of loop
(while, do while and for). It is used with if
condition within the loop.
Syntax:-
jump-statement;
continue;
FUNCTIONS IN C LANGUAGE:-
To perform any task, we can create function.
A function can be called many times. It
provides modularity and code reusability.
Advantage of function:-
1) Code Resuability
2) Code optimization
SYNTAX TO DECLARE FUNCTION:-
return_type function_name(data_type paramet
er...){
//code to be executed
}
Syntax to call function:-
variable=function_name(arguments...);
CALL BY VALUE IN C LANGUAGE:-
In call by value, value being passed to the
function is locally stored by the function
parameter in stack memory location.
If you change the value of function
parameter, it is changed for the current
function only.
It will not change the value of variable
inside the caller method such as main().
EXAMPLE OF CALL BY VALUE:-
#include <stdio.h>
#include <conio.h>
void change(int num) {
printf("Before adding value inside function num=%d \n",num);
num=num+100;
printf("After adding value inside function num=%d \n", num);
}
int main() {
int x=100;
clrscr();
printf("Before function call x=%d \n", x);
change(x);//passing value in function
printf("After function call x=%d \n", x);
getch();
return 0;
}
OUTPUT WINDOW :-
recursionfunction(){
recursionfunction();//calling self function
}
ARRAY IN C:-
Array in C language is a collection or group of
elements (data). All the elements of array
are homogeneous(similar). It has contiguous
memory location.
Declaration of array:-
data_type array_name[array_size];
Eg:-
int marks[7];
Types of array:-
1) 1-D Array
2) 2-D Array
ADVANTAGE OF ARRAY:-
1) Code Optimization
2) Easy to traverse data
3) Easy to sort data
4) Random Access
2-D ARRAY IN C:-
2-d Array is represented in the form of rows
and columns, also known as matrix. It is also
known as array of arrays or list of arrays.
Declaration of 2-d array:-
data_type array_name[size1][size2];
INITIALIZATION OF 2-D ARRAY:-
int arr[3][4]={{1,2,3,4},{2,3,4,5},{3,4,5,6}};
C1 C2 C3 C4
R1 1 2 3 4
R2 2 3 4 5
R3 3 4 5 6
POINTER IN C LANGUAGE
WWW.JAVATPOINT.COM