# CSC COMPUTER EDUCATION, M.K.B.

NAGAR

Session Objectives
Explain 8 Types of Operators

Explain Arithmetic Operators
Understand Arithmetic Expressions

Explain Relational and Logical Operators
Explain the Conditional Operators

Explain the Comma Operators
Explain Input/Output Statement
CSC COMPUTER EDUCATION, M.K.B.NAGAR

CSC COMPUTER EDUCATION.K. M.B.NAGAR .

NAGAR .y=5 x+y -> 21 X-y -> 5 X*y -> 50 x/y -> 2 X%y -> 0 CSC COMPUTER EDUCATION.Arithmetic Operators Arithmetic Operators are used to perform numerical operations Operator + * / % Meaning Addition Subtraction Multiplication Division Modulo Division Example x=10.B. M.K.

y=5 X<y X>y X<=y Result False True False value 0 1 0 >= Greater than or equal to Not Equal to Equal To X>=y True 1 != == CSC COMPUTER EDUCATION.Relational Operators Relational operators are used to test the relationship between two variables or constant Operator < > <= Meaning Less Than Greater Than Less than or Equal to Example x=10.B. M.NAGAR X!=y X==y False False 0 0 .K.

Result X=11 X=9 CSC COMPUTER EDUCATION. (or) ++ variable name. Example X=10. y=5 (x>=5) && (z==„9‟) (X>=6) || (z==„a‟) !(x>8) Result True True False Operator ++ -- Meaning Unary Plus Unary Minus Syntax Variablename++. X--. (or) -. X=10. X++. M. Operator && || ! Meaning Logical And Logical Or Logical Not Example When x=9.Logical Operators Logical operators are used to combine two or more relational expressions.K.variable name.NAGAR . Variablename--. This operator is used to test more than one condition at a time.B.

NAGAR . M.The Assignment Operator In C. the assignment operator(=) can be used for assigning a value to a variable CSC COMPUTER EDUCATION.B.K.

Simple Assignment Operators x=x+1 y=y-1 z=z*(x+y) Y=y/(x+y) X=x%z Equivalent Shorthand Assignment Operators X += 1 Y =.K.B.Variablename <arithmetic Operator>=Expression.NAGAR . M.1 Z *= (x+y) Y /= (x+y) X %= z CSC COMPUTER EDUCATION.

M.K.b=5. } OUTPUT The Result is 10 CSC COMPUTER EDUCATION.NAGAR .c.Simple conditional operations can be carried out with the conditional operator(?:) Expression1 ? Expression 2:expression 3 Condition True Part False Part #include<stdio. C=(a>b)?a:b.B. printf(“The Result is %d".h> void main() { int a=10.c).

h> . # CSC COMPUTER EDUCATION.x+y) scanf(“%d”. ## M. * & -> .K. #include<stdio.NAGAR Meaning Comma Operator Pointer indirection Operator Address Operator Arrow Operator in Structure Dot Operator in Structure String Sizing Operator (prepocessor) Token passing Director Example Z=(x=5.B.Used in applications which require manipulation of individual bits within a word of memory Operators ~ << >> & | ^ Meaning One‟s Complement Left Shift Right Shift Bitwise AND Bitwise OR Bitwise X-OR Operators .y=6.&no).

B. printf("\n Rightmost bit is ON and the result is %d". clrscr(). printf("\n Enter A Number").h> #include<conio.b. printf("\n The Result of AND Operation with 1"). if(ans==0) printf("\n Rightmost bit is OFF"). ans=a&b./* Bitwise Operator Examples */ #include<stdio.and).and.ans. M. else printf("\n Rightmost bit is ON"). printf("\n The Result of OR Operation with 1"). } CSC COMPUTER EDUCATION. scanf("%d". getch(). and=a/b.h> void main() { int a.&a).K.NAGAR . b=1.

NAGAR . M.Unformatted I/O Statement Characters can be read and written in C using the following functions.B. CSC COMPUTER EDUCATION.K.

CSC COMPUTER EDUCATION.K. puts(variablename).NAGAR . M.String Based I/O Operations gets() & Puts() are used to perform Input output operations on a string syntax : gets(variablename).B.

NAGAR . M.variable1.&variable2….).All console I/O functions produce only text based outputs.).K.B.. scanf(“control string”.. printf() scanf() printf(“control string”. CSC COMPUTER EDUCATION.&variable1.variable2….

empname).&empname.salary). } .h> #include<conio.empno).&empno.NAGAR printf(“Enter the Employee Details”) scanf(“%s %d %f”. int empno.Scanf() and Printf() Example #include<stdio. printf(“\n The employee Number is %d”. float salary.B.h> void main() { char empname[20]. CSC COMPUTER EDUCATION.K. printf(“\n The employee Salary is %f”.&salary) printf(“\n The employee Name is %s”. M.

a. scanf("%x". printf("\n u Entered %d\n".K.&a).&a).Reading decimal . clrscr().NAGAR .octal and hexadecimal numbers #include<stdio. printf("\n Enter No in decimal"). printf("\n u Entered %o or %d in decimal\n". printf("\n u Entered %x or %d\n". printf("\n Enter No in octal").h> #include<conio. M.a).h> void main() { int a. } CSC COMPUTER EDUCATION.&a).a. scanf("%d". scanf("%o".B.a). printf("\n Enter No in Hexadecimal"). getch().a).

M.Type Conversion This is used to convert one data type to another data type. The automatic type conversions for evaluating an expression are given below - For example.NAGAR .K.B. CSC COMPUTER EDUCATION.

B.The sizeof operator sizeof is a unary compile-time operator The use of the sizeof operator shall be clear from the following example - CSC COMPUTER EDUCATION.K. M.NAGAR .

strings.float at a time.Session Summary The getchar().getch().getche() deals with single character input  The functions gets() and puts() deals with string input and output respectively  printf() display any number of characters.strings.NAGAR . integers.B.integers. float can be received at a time  scanf() receives any number of characters.  getchar() doesnot require any argument  gets() require a single argument  In a scanf() strings with spaces cannot be accessed until ENTER key is pressed.  In a gets() strings with any number of spaces can be accessed. CSC COMPUTER EDUCATION.K. M.

EXERCISES 1. Write a program to calculate Simple and Compound Interest? 5.NAGAR . Write a program for swapping two numbers using two varaibles? 4. Describe the different specifiers in scanf() function? 2. Write a program to find the area of the circle (area=3. State the use of ambersand statement(s) in a scanf() statement? 3. Write a program to convert temperature in centigrade to farenheit? 7. M. Write a program to convert a decimal Number into its equivalent octal & Hexadecimal number using Format specifiers? 6.K.B.14*r2)? CSC COMPUTER EDUCATION.