C Language Full Details Notes.
∎ Why C language is so important?
➤ worth to know about c language
- oracle is written in c
- core libraries of android are written in c
- MySQL is written in c
- Almost every device driver is written in c
- Major part of web browser is written in c
- Unix operating system is developed in c
- c is the worlds most popular programming language
➤ For students
- C is important to build programming skills
- C covers basic features of all programming language.
- Campus recruitment process
- C is the most popular language for hardware dependent programming
∎ History of C language.
- Developer of BCPL ( Basic combined programming language) (Martin Richards)
develop in 1966.
- Developer of B language (Ken Thompson) develop in 1969.
Also developer of Unix Operating system.
He also developed first mater level chess called Belle in 1980.
- Developer of C language in 1972 (Dennis Richie)
AT AT & T's Bell Labs, USA
- Co-developer of unix operating system.
∎ What is 0 and 1.
- There is nothing like 0 and 1 in computer. there is no physical significance of 0 and 1
- Any information can encoded as a sequence of 0 and 1
∎ Program and process.
- Set of sequential instruction is called program.
- Active state of a program is called process.
∎ Constant
- Any information is constant
- Data=information=constant
∎ Type of Constants
(i) Primary Constants
(i) integer
(ii) Real
(iii) Character
(ii) Secondary Constants
(i) Array
(ii) String
(iii) Pointer
(iv) Union
(v) Structure
(vi) Enumerator
∎ Variables
- Variables are the name of memory locations where we store data.
∎ Rules for constructing variable names in C
- Variable name is any combination of alphabet, digit and underscore.
- (A-Z) the first character must be a letter
- Space is not allowed between names of identifiers
- Special symbols are not allowed (&*^#$@)
- Not allow white space
- A valid variable name cannot start with digit
- Underscores_can be used
- the reserve word are not allowed (int, float, char etc.)
∎ Keywords
- predefined word
- reserved word
- There are 32 Keywords in C language
∎ List of Keywords
auto double goto signed unsigned
Break default if sizeof void
case enum int static volatile
char else long struct while
const extern register switch
do for return typedef
continue float short union
∎ Instruction
- program statements are called instruction.
- instruction are commands
∎ Type of instruction
- data type declaration instruction
-input output instruction
- arithmetic instruction
- control instruction
∎ Data Type
- int
- char
- float
- double
- void
- it is also known as primitive data type
∎ Size of Data Type in C
| Type | Range | Size (in bytes) |
| unsigned char | 0 to 255 | 1 |
| signed char or char | -128 to +127 | 1 |
| unsigned int | 0 to 65535 | 2 |
| signed int or int | -32,768 to +32767 | 2 |
| unsigned short int | 0 to 65535 | 2 |
| signed short int or short int | -32,768 to +32767 | 2 |
| unsigned long int | 0 to +4,294,967,295 | 4 |
| signed long int or long int | -2,147,483,648 to +2,147,483,647 | 4 |
| long double | 3.4E-4932 to 1.1E+4932 | 10 |
| double | 1.7E-308 to 1.7E+308 | 8 |
| float | 3.4E-38 to 3.4E+38 | 4 |
∎ Standard input/output Device
- Keyboard is standard input device
- Monitor is standard output device
∎ printf()
- printf() is not a keyword
- printf() is a predefined function
- Two type of messages
- printing text as it is
- printing value of expression or value of variable.
∎ First program in c language
#include<stdio.h>
#include<conio.h>
void main()
{
printf("Hello India");
getch();
}
____________________________________
#include <stdio.h>
#include <conio.h>
void main ()
{
clrscr(); // to clear screen
printf("Hemant");
printf("\h kumar");
getch();
}
#include<stdio.h>
#inclode<conio.h>
void main()
{
clrscr();
gotoxy(40,13);
printf("Hemant \h kumar");
getch();
}
____________________________________
#include<stdio.h>
#inclode<conio.h>
void main()
{
int a=4,b=5;
clrescr();
printf("%d%d",a,b);
getch();
}
/*
Format specifier
%d int
%f float
%c char
%if double
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a=4, b=5;
clrscr();
printf("sum of %d and %d is %d",a,b,a+b);
getch();
}
_______________________________________
scanf()
🔘 scanf() is not a keyword
🔘 scanf() is a predefined function
🔘 scanf("format specifier",variable address);
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
Scanf("%d",&x);
printf("square of % is %d",x,x*x);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
clrscr();
printf("enter a number :=");
Scanf("%d",&x);
printf("square of %d is %d",x,x*x);
getch();
}
ASCII Codes :-
🔘 ASCII stand for American standard code for Information Interchange
🔘 ASCII Code is the numerical representation of a character such as 'a' or '@' or an action of some sort.
ASCII is an old encoding :-
🔘 ASCII was developed a long time ago and now used the non - printing Characters are rarely used for their original purpose.
🔘 ASCII was actually designed for use with teletypes.
🔘 A teleprinter (teletypewriter Teletype or TTY) is an electromechanical typewriter that can be used to send and received type massages form point to point and point - to - multipoint over various types of communications channels.
Arithmetic Instruction :-
An instruction which is used to manipulate data using operators, is known as Arithmetic instructions.
Operator Groups :-
🔘 Unary operators
🔘 Arithmetic operators
🔘 Bitwise operators
🔘 Relational operators
🔘 Logical operators
🔘 Conditional operators
🔘 Assignment operators
Unary operators :-
+ , - , ++ , -- , size of ()
++ (increment operator)
-- (decrement operator)
#include<stdio.h>
#include<conio.h>
void main()
{
int x = 3;
clrscr();
x++; // x = x +1
printf("%d", x);
getch ();
}
____________________
#include<stdio.h>
#include<conio.h>
void main();
{
int x = 3
clrscr();
x++ // post increment
printf("%d",x);
++x; // pre increment
printf ("%d",x);
getch ();
}
__________________
#include<stdio.h>
#include<conio.h>
void main ();
{
int x = 3 , y ;
clrscr();
y = x ++ ;
printf("%d%d" , X , y);
getch ();
}
sizeof ():-
sizeof (data type)
sizeof (variable)
sizeof (constant)
#include<stdio.h>
#include<conio.h>
void main ();
{
int x;
clrscr ();
x = sizeof(int);
printf("%d" , x);
getch ();
}
_____________________
#include<stdio.h>
#include<conio.h>
void main ();
{
int x , y ,z;
x = sizeof(34);
y = sizeof(3.56);
z = sizeof('a');
printf (" %d %d %d " , x , y , z);
getch ();
}
Modulo operator :-
5 % 2 = 1
-5 % 2 = -1
5 % -2 = 1
-5 % -2 = -1
Bitwise Not operator (~) :-
Bitwise
Unary
Bitwise & Operator :-
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
example :-
int x;
x = 23 & 56;
23 = 0000 0000 0001 0111
56 = 0000 0000 0011 1000
16 = 0000 0000 0001 0000
Bitwise | (or) operator
0 | 0 = 0
0 | 1 = 1
1 | 0 = 1
1 | 1 = 1
example :-
int x ;
x = 23 | 56 ;
23 = 0000 0000 0001 0111
56 = 0000 0000 0011 1000
63 = 0000 0000 0011 1111
Bitwise ^ (XOR) Operator :-
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 0 = 0
example :-
int x ;
x = 23 ^ 56;
23 = 0000 0000 0001 0111
56 = 0000 0000 0011 1000
47 = 0000 0000 0010 1111
Right shift operator :- (>>)
int x ;
x = 56 >> 2;
56 = 0000 0000 0011 1000
14 = 0000 0000 0000 1110
Left shift (<<) operator :-
int x;
x = 56 << 3;
56 = 0000 0000 0011 1000
448 = 0000 0001 1100 0000
Relational operators :-
< , > , < = , > =
= = , ! =
Remember :-
🔘 Relational operator always fields result either 0 or 1
🔘 Every non - zero value is True and zero is false
🔘 True is 1 and false is 0
#include<stdio.h>
#include<conio.h>
void main ();
{
int x ;
clrscr();
x = 3 > 4;
printf ("%d" , x);
getch ();
}
____________________
#include<stdio.h>
#include<conio.h>
void main ();
{
int x ;
clrscr ();
x = 3<=4 ;
printf("%d", x);
getch ();
}
_____________________
#include<stdio.h>
#include<conio.h>
void main ();
{
int x;
clrscr();
x = 4!= ;
printf("%d", x);
getch ();
}
#include<stdio.h>
#include<conio.h>
void main ();
{
int x;
clrscr();
x = 5 > 4 > 3 ;
printf(' %d ", x);
getch ();
}
Logical operator :-
NOT !
AND & &
OR | |
NOT Operator
🔘 It is also unary operator
🔘 Priority level as same as of unary operators
🔘 It inverts the truth value of statement
!T = F
!F = T
#include<stdio.h>
#include<conio.h>
void main ();
{
int y , x = 5 ;
clrscr();
y = !x > 4;
printf("%d " , Y);
getch ();
}
__________________
#include<stdio.h>
#include<conio.h>
void main ();
{
int y , x = 5 ;
clrscr();
y = x > 4 && x < 10;
printf("%d", y );
getch ();
}
&&
#include<stdio.h>
#include<conio.h>
void main ();
{
int y , x = 5
clrscr ();
y = x < 4 || x < 10 ;
printf(' %d ", y);
getch ();
}
| |
Conditional operator ( ? : ) :-
- Ternary operator
- Conditional operator
Syntax :-
exp1 ? exp2 : exp3
x > 4 ? printf("A") : printf("B");
_________ ________
True False
#include<stdio.h>
#include<conio.h>
void main ();
{
int a , b ;
printf("enter two number")
Scanf("%d %d ". & a, & b );
printf(" Greatest number is %d " , a > b ? a : b );
getch ();
}
Compound Assignment operator :-
+ = , - = , * = , / = , % = , & = , | = , ^ =
int x = 5;
x + = 4; // x = x + 4
x * = 3 ; // x = x * 3
x % = 2 // x = x % 2
Control Instructions :-
Decision Control Instruction
Iterative control Instruction
Switch Case Control Instruction
go to Control Instruction
Decision Control Instruction
If
If else
Conditional operator (?:)
*Write a program to check wether a number is positive or not *
#include<stdio.h>
#include<conio.h>
void main ();
{
int x;
clrscr ();
printf("enter a number");
Scanf("%d " , & x );
if ( x > 0)
{
printf("positive number");
}
if (x< = 0 )
{
printf(" Non positive Number ");
}
getch ();
}
If else :-
syntex :-
if (condition)
{
line 1 ;
line 2 ;
-------
}
else
{
line 1;
line 2 ;
--------
}
#include<stdio.h>
#include<conio.h>
void main ();
{
int x ;
clrscr();
printf("enter a number");
Scanf("%d" , & x );
if ( x > 0 )
{
printf("positive number ");
}
else
{
print ("Non positive")
}
getch ();
}
__________________
#include<stdio.h>
#include<conio.h>
void main ();
{
int x;
clrscr ();
printf('"enter a number" );
Scanf ("%d " , & x);
if (x > 0 )
printf("positive");
else
printf("Non Positive");
getch ();
}
Conditional operator (?;)
Syntex :-
Condition ? Statement 1 : Statement 2;
#include<stdio.h>
#include<conio.h>
void main ();
{
int x;
clrscr ();
printf("enter a number");
Scanf("%d " , & x );
x > 0 ? printf("positive"); printf("Non positive");
getch ();
}
Selective Assignment :-
x = a > b ? a : b ;
#include<stdio.h>
#include<conio.h>
void main ();
{
int x , y , max;
clrscr ();
printf("enter tow numbers");
Scanf("%d %d " , & x , & y );
max = x > y ? X : y ;
x > 0 ? printf("greater number is %d ",max );
getch ();
}
Nested if else:-
if (some condition) : if (condition)
{ : }
if (some condition) :
{ : }
: else
} : {
else : if (condition)
{ : {
} :
} : }
else : else
{ : {
: }
} : }
/ / Largest among 3 variables using nested if
#include<stdio.h>
#include<conio.h>
void main ();
{
int a ,b , c;
printf("enter three number");
Scanf("%d %d %d " , & a , & b , & c );
if (a>b)
{
if (a > c )
printf("%d " , a );
else
printf("%d " , c);
}
else
{
if ( b > c)
printf("%d " , b);
else
printf("%d" , c);
}
getch ();
}
If else ladder:-
syentex :-
if ( )
Statement ;
else if ( )
Statement ;
else if ( )
Statement ;
else if ( )
Statement ;
#include<stdio.h>
#include<conio.h>
void main ();
{
int marks;
printf("enter your marks");
Scanf("%d " , & marks);
x > 0 ? printf("positive"); printf("Non positive");
else if (marks > 90 )
printf("Grade - A");
else if (marks >80)
printf("Grade - B");
else if (marks >70)
printf("Grade- C");
else
printf("Grade - D ");
getch ();
}
Loop
Iterative Control Instructions :-
While
do while
for
#include<stdio.h>
#include<conio.h>
void main ();
{
int i = 1 ; / / Initialization
clrscr ();
while (i < = 5 ) / / Conditional
{
printf("STATEMENT \ h");
i + + ; / / Flow
}
getch ();
}
*Syntex compariso :-
main ( )
{
int i =1
while (i < = 5)
{
printf("hemant");
i + + ;
}
getch ();
}
---------------------------------------------------------------------------------------------------------------
main ( )
{
int i =1
do
{
printf("hemant");
i + + ;
}
while (i < = 5)
getch ();
}
----------------------------------------------------------------------------------------------------------------
main ( )
{
int i
for (i = 1 ; i < = 5 ; i + +)
{
printf("hemant");
}
getch ();
}
*Break :-
The keyword break can be use used is loop body or in switch body.
The purpose if break is to terminate loops execution immediately as it encounters.
example :-
#include<stdio.h>
#include<conio.h>
void main ();
{
int i = 1 , x ;
{
printf("enter a number");
Scanf("%d %d " , & x);
if ( x > 0 )
break;
i + + ;
}
i = 6 ? printf("ends normally ; printf("appliod braek");
getch ();
}
Switch Control
*Syntax :-
Switch (expreession)
{
Case constant : Code ;
Case constant : Code ;
Case constant : Code ;
Case constant : Code ;
default : code ;
}
*example :-
Write a menu driven program with the following options;
1. Addition
2. Odd - even
3. Printing first natural N numbers
4. exit
#include<stdio.h>
#include<conio.h>
void main ()
{
int choice ,a ,b ,s
while (1)-
clrscr ();
printf(" \n 1. Addition");
printf(" \n 2. Odd - even")
printf(" \n 3. printing N number");
printf(" \n 4. exit");
printf("\n\n enter ypur choice");
Scanf(%d ". & chioce );
Switch (chioce)
{
Case 1 :
printf("Enter tow numbers");
Scanf("%d %d ", & a , & b );
s = a + b ;
printf("in sum is %d", S);
break;
Case 2:
printf("enter a number");
scanf("%d ", & a);
if (a % 2 = = 0)
printf("even number");
else
printf("odd number");
break;
Case 3 :
printf("enter a number");
scanf("%d" , & a );
for ( b=1 ; b < =a ; b + + )
print ("%d" , b);
break;
Case 4 : exit (0);
default ;
printf("Invalid choice");
}
getch();
}
*What is function ( )?
Piece if cide to accomplish certain poeration .
It has a name for identification
They area if two types
- Predefined function
- user defined function
*Remember :-
Program muat have at least one function
Function names must be unique
Function is an operation , Once defined can be used many times .
One function is the program must be main
Function consumes memory only when it is invoked and released from RAM as soon as it finishes its job.
*Benefits of function :-
Modularization
easy to read
easy to debug
easy to modify
Avoids rewriting if sane code over and over
Better memory utilization
*Ways to define a function
Takes Nothing , Returns Nothing
Takes Something , Returns Nothing
Takes Nothing , Returns Something
Takes Something , Returns Something
/ / Takes Nothing , Return nothing
#include<stdio.h>
#include<conio.h>
void main ()
{
clrscr ( );
add ( );
getch ( );
}
void add ( )
{
int a ,b , c;
printf("enter tow numbers");
Scanf("%d %d ", & a , & b );
c = a + b;
printf("sum is old %d " , C);
}
/ / Takes Something Return Nothing
#include "stdio.h"
#include "conio.h"
void add (int , int );
void main()
{
int x , y ;
/ / void add (int , int ); यहाँ à¤ी use कर सकते है आप
clrscr();
print("enter tow numbers");
Scanf("%D ", & x , & y);
add ( x , y ) ; | | Actual Argument /call by value
getch();
}
void add ( int a , int b ) / / formula Arguments
{
int c ;
c = a+ b
printf("sun is %d " , C );
}
/ / Takes Nothing Returns Something
#include<stdio.h>
#include<conio.h>
int add (void);
void main ( )
{
int s ;
clrscr ( ) ;
s = add ( ) ;
printf("sum is %d " , S);
getch ( );
}
int add ( )
{
int a , b , c ;
printf("enter tow numbers");
Scanf( "%d %d " , & a < & b );
c = A + b ;
return (c);
}
/ / Takes something Returns Something
#include "Stdio.h"
#include "conio.h"
int add ( int , int );
void main ( )
{
int s , x , y ;
clrscr ( );
printf("enter tow numbers");
Scanf(" %d %d " , & x , & y );
s = add ( x , y );
printf("sum is %d " , S);
getch ( ) ;
}
int add (int a , int b)
{
int c ;
c = a + b;
return ( c) ;
}
*Recursion :-
Function calling itself is called Recursion
*Arrays :-
Array is also linear collection of similar elements
Array is also known as subscript variable
Array is a group of variable
0 1 2 3 4 5 6 7 8 9
#include<stido.h>
#include<conio.h>
void maik();
{
int a[ 10 ] , i sum = 0 ;
float avg;
clrscr ( ) :
printf("enter 10 numbers");
for ( i = 0 ; i < = 9 ; i + + )
Scanf(" %d " , & a [ i ]);
for ( i = 0 ; i < = 9 ; i + + )
avg = sum / 100;
printf("Average is % f " ; avg);
getch ( ) ;
}
*Declaration of Arrays :-
int a [ ] ; error
int a [ 5 ] ;
int a [ 5 ] = { 9 , 6 , 8 , 0 , 2};
int a [ ] = { 9 , 6 , 8 , 0 , 2 };
*Two Dimensional Arrays :-
int b [ 2 ] [ 3 ] ;
#include<stdio.h>
#include< conio.h>
void main ()
{
int A [ 3 ] [ 3 ] , B [ 3 ] [ 3 ] , c [ 3 ] [ 3 ] , i , j ;
(Working in Process).........................


.png)
.png)

0 Comments