C Programming - Lecture 2
C Programming - Lecture 2
1/26
Operators
2/26
Expression
3/26
Operators and Expressions
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and decrement operators
6. Conditional operators
7. Bitwise operators
8. Special operators
4/26
Arithmetic operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Reduction(Remainder from integer
division)
6/26
Logical Operators
Operator Meaning
|| logical OR
! logical NOT
7/26
Assignment operator
Assignment operator is = .
The assignment statement of the form
var = expression;
var = var;
8/26
Shorthand Assignment operators
9/26
Shorthand Assignment Operators
Example
10/26
Assignment Operators Priority
11/26
Bitwise Operator
12/26
C increment and decrement operator
13/26
Prefix and postfix
14/26
Prefix and postfix Example
15/26
Conditional Operator
16/26
Compare Conditional Operator
& if..else statement
Q13.Compare Conditional Operator & if…else statement
A ternary operator “?:” is available in C to construct
conditional expressions of the form
exp1? exp2: exp3 ;
Consider the following statements.
a=10;
b=15;
x= (a>b)? a: b;
In other words, the conditional expression is sort of an
if/else statement.
if(a>b)
x=a;
else
x = b;
17/26
Special operator (1/2)
For example:
int a[5] = { 1, 2, 3, 4, 5 };
For example:
int a = 1;
int *b = &a;
*b = *b + 1;
18/26
Special operator (2/2)
19/26
Symbolic constant
Example:
#define PI 3.141593
#define TRUE 1
#define FALSE 0
20/26
INPUT AND OUTPUT FUNCTION
Example:
getchar() ;
putchar () ;
scanf () ;
printf () ;
gets();
puts () ;
21/26
GETCHAR FUNCTION
22/26
PUTCHAR FUNCTION
23/26
Puts and gets function
For example:
char name[30];
gets(name);
puts(name);
24/26
printf and scanf function
For Example:
scanf(“%d”, &sum);
For example:
printf(“ Masters in Information Technology”);
printf(“ Sum is equal to:%d”, sum);
25/26
Thank You
26/26