Presentation is loading. Please wait.

Presentation is loading. Please wait.

Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator.

Similar presentations


Presentation on theme: "Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator."— Presentation transcript:

1 Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator Conditional operator

2 Arithmetic operator It is used to carry out arithmetic operations like addition, subtraction etc, Eg: +, -, *, / etc,

3 Sample program #include // Header File #include int b=10; //Global Declaration void main ( ) /* main is the starting of every c program */ { int a,c; //Local Declaration clrscr( ); scanf(“%d”,&a); printf(“ \n The sum of the two values:”); c = a+b; printf(“%d”,c); getch( ); }

4 Division operator on Different Data Type OperationResultExample int/intint5/2 = 2 int/realreal5/2.0 = 2.5 real/intreal5.0/2 = 2.5 real/realreal5.0/2.0 = 2.5

5 Sample program #include void main ( ) { int a=10,b=4,c; float d=3,e; clrscr( ); c = a/b; printf(" \n value a/b is:%d",c); e = a/d; printf("\n value a/d is:%f",e); getch( ); }

6 Output value a/b is:2 value a/d is:3.333333

7 Relational operator It is used to compare two or more operands. Eg :, =, != etc,. 5 < 9 which will return 1

8 Logical operator It is used to combine the result of two or more condition. AND(&&) OR (||) NOT (!) are Logical operators. Eg: (i>10)&&(j>5). (i>10)||(j>5) etc,.

9 Sample program #include void main ( ) { int a=10,b=3,c=5,e; clrscr( ); if(a>b) // relational operator { printf(" \n a is bigger than b"); } if((a>b)&&(a>c)) //Logical operator { printf(" \n a is biggest"); } getch( ); }

10 Output a is bigger than b a is biggest

11 Assignment operator It is used to assign a value or expression etc to a variable. Eg: a =10. a = b a = b + c etc,.

12 Assignment operator(Cont) Compound operator It is also used to assign a value to a variable. Eg: x + = y means x = x + y Nested operator It is used for multiple assignment. Eg: i = j = k = 0;

13 Sample program #include int b=10; void main ( ) { int a=3,b=5; clrscr( ); a+=b; // a= a+b printf(" \n The sum of the two values:%d",a); getch( ); }

14 Output The sum of the two values:8

15 Increment or decrement operator(Unary) It is used to Increment or decrement an operand. Eg: ++x (Pre Increment), x++ (Post Increment), --x (Pre Decrement), x-- (Post Decrement).

16 Sample Program #include void main ( ) { int a=5; clrscr( ); printf(" \n Post increment Value:%d",a++); printf(" \n Pre increment Value:%d",++a); printf(" \n Pre decrement Value:%d",--a); printf(" \n Post decrement Value:%d",a--); getch( ); }

17 Output Post increment Value:5 Pre increment Value:7 Pre decrement Value:6 Post decrement Value:6

18 Bitwise operator It is used to manipulate data at bit level. Eg: a=5 i.e 0000 0101 b=4 i.e 0000 0100 Then a & b = 0000 0100 a | b = 0000 0101 etc,.

19 Sample program #include void main ( ) { int a=5,b=4,c; //char a=5,b=4,c; clrscr( ); c = a&b; printf(" \n value a&b is:%d",c); getch( ); }

20 Output value a&b is:4

21 Conditional Operator (or) Ternary Operator It is used to checks the condition and execute the statement depending on the condition. Eg: C = a > b ? a:b

22 Sample Program #include void main ( ) { int a=5,b=8,c; clrscr( ); c = a>b?a:b; //Conditional operator printf(" \n The Larger Value is%d",c); getch( ); }

23 Output The Larger Value is 8

24 Special Operator comma operator (, ) sizeof operator pointer operator (&, *) etc,.

25 #include void main ( ) { int c; clrscr( ); printf(" \n size of int is:%d",sizeof c); getch( ); }

26 Output size of int is: 2

27 Expression An expression represent data item such as variable, constant are interconnected using operators. Eg: ExpressionC Expression a + b + c a 2 +b 2 a*a + b*b

28 Operator Precedence & Associativity The arithmetic expressions evaluation are carried out based on the precedence and associativity. The evaluation are carried in two phases. – First Phase: High Priority operators are evaluated. – Second Phase: Low Priority operators are evaluated.

29 PrecedenceOperator High*, /, % Low+, -

30 Example 5 - 20/4 + 3*3 – 1 = 5 - 5 + 9 – 1 = 0 + 9 – 1 = 9 – 1 = 8

31 Example 5 – (20/4) + 3*(3 – 1) = 5 - 5 + 3*2 = 5 - 5 + 6 = 6

32 Type Conversion Converting the type of an expression from one type to another type. Eg: x = (int)10.45

33 Sample Program #include void main ( ) { int c; clrscr( ); c=(int)10.45; printf("\nOutput is:%d",c); getch( ); } OUTPUT Output is:10

34 Input/Output Function Input/Output Function Unformatted Formatted Output printf() fprintf() Input scanf() fscanf() Input getc() gets() getchar() Output putc() puts() putchar()

35 Formatted Input/Output C uses two functions for formatted input and output. Formatted input : reads formatted data from the keyboard. Formatted output : writes formatted data to the monitor.

36 Formatted Input and Output

37 Standard Output The standard output file is the monitor. Like the keyboard, it is a text file. When you need to display data that is not text, it must be converted into to the text before it is written to the screen.

38 Format of printf Statement

39 Formatted Input (scanf) The standard formatted input function in C is scanf (scan formatted). scanf consists of : a format string. an address list that identifies where data are to be placed in memory. scanf ( format string, address list ); ( “ %c ….%d …..%f ….. ”, &a, ….&i, …..,&x …..)

40 Format of scanf Statement

41 Character Test Function It is used to test the character taken from the input. isalpha(ch) isdigit(ch) islower(ch) isupper(ch) tolower(ch) toupper(ch) etc,.


Download ppt "Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator."

Similar presentations


Ads by Google