Introduction To C
Introduction To C
Language: C
Essay Program
C Tokens
4
Constants
5
Escape Sequences
6
Operators
Arithmetic(+,-,*,/,%)
Increment & Decrement(++,--)
Relational(<,>,<=,>=,==,!=)
Logical(&&,||,!)
Conditional/ Ternary(?:)
Bit-wise(&,|,~,<<,>>)
Assignment(=)
Special(,,*,&,sizeof(),.and->)
7
Precedence of Operators
(),[],.,->
Unary operator(!,~,+,-,++,--,&,*,sizeof)
Arithmetic(*,/,%,+,-)
Left and right shift
Relational
Bitwise
Logical
Conditional
Shorthand
Comma
8
Associativity of operators
9
Samples
10
Samples
Coding Output
#include<stdio.h> 15
#include<Conio.h> 15
int main() 15 206592320
{
int a,b;
a=5,b=10;
printf("%d",a+b);
printf("\n%d",a+b,a);
printf("\n%d\t%d",a+b);
return 0;
}
11
Samples
Coding Output
int a,b;
float c,d;
a=10,b=4;
c=5.5,d=4;
printf("%d\t%d",a/b,a/c); 2 -536870912
printf("\n%d\t%d",c/a,c/d); -1610612736 0
printf("\n%d",a%b); 2
12
Samples
Coding Output
int a,b;
float c,d;
a=10,b=4;
c=5.5,d=4;
printf("%d\t%f",a/b,a/c); 2 1.818182
printf("\n%f\t%f",c/a,c/d); 0.550000 1.375000
printf("\n%d",a%b); 2
13
Samples
Coding Output
int a,b;
float c,d;
a=10,b=-4;
c=-5.5,d=4;
printf("%d\t%f",a/b,a/c); -2 -1.818182
printf("\n%f\t%f",c/a,c/d); -0.550000 -1.375000
printf("\n%d",a%b); 2
printf("\n%d",-a%b); -2
14
Shifting Operators
15
Logical Operator
16
Logical OR
int main()
{
int a=1,b=0; First:a=1,b=0,c=1
int c,d; Second:a=0,b=1,c=1,d=1
c=a||++b;
printf(“First:a=%d,b=%d,c
=%d",a,b,c);
d=--a||++b;
printf(“Second:a=%d,b=%
d,c=%d,d=%d",a,b,c,d);
}
17
Logical AND
{ {
int a=5,b; int a=5,b;
b=a++ + a++; b= ++a + a++;
printf("a=%d b=%d",a,b); printf("a=%d b=%d",a,b);
} }
Output: Output:
19
Increment/Decrement
{ {
} }
Output: Output:
20
printf()
printf("""Hello"""); printf(""Hello"");
21
printf()
• printf("%d",(printf("Hello")));
Hello5
• printf("%d",(printf("%d",(printf("Hello")))));
Hello51
22
printf()
• printf("%d",(scanf(“%d %d“,&a,&b)));
2
• printf("%d",(scanf(“%c %d“,&a,&b)));
2
23
24
25