Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Raja Ranjit Kishore Govt.

Polytechnic
Ramgarh, Binpur-I, Jhargram
Department of Computer Science & Technology
2nd Year-3rd Semester
E-Contents : Programming in C
Unit : Basic of C, Unit No : 1

Developed By:
Subhajyoti Mahata
Lecturer, Computer Science & Technology
Raja Ranjit Kishore Govt. Polytechnic, Ramgarh
Contents
 Operators

 Operator precedence

 Associativity of operators

 Type conversion and Typecasting


Operators
 An operator is a symbol that operates on
value or variable.

 Arithmetic Operator
Cont’d…
 Increment (++) and Decrement (--)
Operators

int a = 2, b = 5;

++a; // a : 3
--b; // b : 4
Cont’d…
 Assignment Operator
Cont’d…
 Relational Operators
Cont’d…
 Logical Operator

int a = 5, b = 5, c = 10, result;

result = (a == b) && (c > b); // result : 1


result = (a == b) || (c < b); // result : 1
result = !(a == b); // result : 0
Cont’d…
 Bitwise Operator
Cont’d…
 Conditional Operator

 Syntax : test expression ? expression :


expression

int a = 5, b;

b = a>2? a : 0; // b : 5
b = a>6? a : 0; // b : 0
Cont’d…
 Comma Operator
int a, c = 5, d;
 sizeof Operator
char a;
sizeof(a); // return 1
 Prefix Operator
int a = 5, b;
b = ++a; // b : 6
 Postfix Operator
int a = 5, b;
b = a++; // b : 5
Operator precedence
 Operator precedence determines which
operator is performed first in an expression.
Operators associativity
 It is used when two operators of same precedence
appear in an expression.
 Associativity can be either Left to Right or Right to Left.
Type conversion and Type casting
 A type cast is basically a conversion from
one type to another.

 Implicit Type Conversion


int x = 10;
float y = x + 2.5; // y : 12.500000

 Explicit Type Conversion or Type casting


double x = 1.2;
int sum = (int)x + 1; // sum : 2
Resources

 Let us C, Yashavant Kanetkar, BPB Publication

 Programing in ANSI C, E. Balagurusamy, TMH Publication

 www.geeksforgeeks.org

 www.programiz.com/c-programming

 www.tutorialspoint.com/cprogramming
Questions or Assignments

 How many types of operator in C?

 What are post-increment and pre-increment


operator?

 What is the difference between operator


precedence and operator associativity?

 What is the difference between type conversion


and type casting?
Thank You

You might also like