C Progragramming Language Tutorial
C Progragramming Language Tutorial
C
Programming
C is mother language of all programming
language.
It is a popular computer programming
language.
It is procedure-oriented programming
language.
It is also called mid level programming
language.
C programming language was developed in
1972 by Dennis Ritchie at bell laboratories
of AT&T(American Telephone & Telegraph),
located in U.S.A.
Dennis Ritchie is known as founder of c
language.
It was developed to be used in UNIX
Operating system.
It inherits many features of previous
languages such as B and BPCL.
Language year Developed By
ALGOL 1960 International Group
BPCL 1967 Martin Richards
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K&RC 1978 Kernighan & Dennis
Ritchie
ANSI C 1989 ANSI Committee
ANSI/ISO C 1990 ISO Committee
C99 1999 Standardization
Committee
There are many features of c language are given below.
}
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
It is better if you have to execute the code
at least once.
Syntax:-
do{
//code to be executed
}while(condition);
It is better if number of iteration is not
known by the user.
Syntax:-
while(condition){
//code to be executed
}
It is good if number of iteration is known by
the user.
Syntax:-
for(initialization;condition;incr/decr){
//code to be executed
}
it is used to break the execution of loop
(while, do while and for) and switch case.
Syntax:-
jump-statement;
break;
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;
Note:- you can see the example of above all
control statements on.
www.javatpoint.com/c-if else
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
return_type function_name(data_type paramet
er...){
//code to be executed
}
Syntax to call function:-
variable=function_name(arguments...);
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().
#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;
}
Before function call x=100
Before adding value inside function num=100
After adding value inside function num=200
After function call x=100
In call by reference, original value is
modified because we pass reference
(address).
Note : Learn Call by reference in details with
example via JavaTpoint.
#include <stdio.h>
#include <conio.h>
void change(int *num) {
printf("Before adding value inside function num=%d \n",*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 reference in function
printf("After function call x=%d \n", x);
getch();
return 0;
}
Before function call x=100
Before adding value inside function num=100
After adding value inside function num=200
After function call x=200
A function that calls itself, and doen't
perform any task after function call, is know
as tail recursion. In tail recursion, we
generally call the same function with return
statement.
Syntax:-
recursionfunction(){
}
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
1) Code Optimization
2) Easy to traverse data
3) Easy to sort data
4) Random Access
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];
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 is a user defined data_type which
create the special types of variables.