This document discusses different types of operators in C programming language including arithmetic, relational, logical, assignment, increment/decrement, and conditional operators. It provides examples of each operator type and explains their usage and functions. The key points are:
1. Operators allow mathematical and logical manipulations in C code. Common operator categories include arithmetic, relational, logical, assignment, increment/decrement, and conditional.
2. Arithmetic operators are used for calculations. Relational operators compare values. Logical operators combine relational expressions. Assignment operators assign values to variables.
3. Increment/decrement operators add or subtract 1 from a variable. The prefix notation uses the new value in the statement while
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
24 views
Operator and Expressions
This document discusses different types of operators in C programming language including arithmetic, relational, logical, assignment, increment/decrement, and conditional operators. It provides examples of each operator type and explains their usage and functions. The key points are:
1. Operators allow mathematical and logical manipulations in C code. Common operator categories include arithmetic, relational, logical, assignment, increment/decrement, and conditional.
2. Arithmetic operators are used for calculations. Relational operators compare values. Logical operators combine relational expressions. Assignment operators assign values to variables.
3. Increment/decrement operators add or subtract 1 from a variable. The prefix notation uses the new value in the statement while
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11
Chapter 3
Operator and Expressions
Operator An operator is a symbol that tells the compiler to perform certain mathematical or logical manipulations. C operator can be classified into a number of categories: 1. Arithmetic Operator 2. Relational Operator 3. Logical Operator 4. Assignment Operator 5. Increment and decrement Operator 6. Conditional Operator 7. Bitwise Operator 8. Special Operator Arithmetic Operator These are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus. Program 3.1 (Text Book = 53) #include<stdio.h> Output: void main () { Enter days
int months, days ; 265
Months = 8 Days = 25
printf("Enter days\n") ; Enter days
scanf("%d", &days) ; 364 Months = 12 Days = 4 months = days / 30 ; Enter days days = days % 30 ; 45 Months = 1 Days = 15 printf("Months = %d Days = %d", months, days) ; Relational Operator • These operators are used to compare the value of two variables. • The value of relational operator is either one or zero. • It is one if the specified relation is true and zero if the relation is false. Logical Operator • Logical operator combines two or more relational expressions. • Logical expressions yields a value of one or zero according to true or false. Assignment Operator • These are used to assign the values for the variables in C programs. • C also has a set of shorthand assignment operators. Shorthand Assignment Operator
• What appears on the left-hand side need not to be
repeated and therefore it becomes easier to write. • The statement is more concise and easier to read. • The statement is more efficient. Increment and Decrement Operator • Increment operator is denoted by ++ and decrement operator is denoted by -- • The operator ++ adds 1 to the operand, while -- subtracts 1. • Format: ++m ; m++ ; --m ; m-- • If increment or decrement operator is used before variable, it is called prefix notation. • If increment or decrement operator is used after variable, it is called postfix notation. Difference between Prefix and Postfix notation • In case of prefix notation, compiler add or subtract 1 with the initial value of variable and the new value of variable is used in the same statement. • In case of postfix notation, compiler add or subtract 1 with the initial value of variable and the new value of variable is used in the next statement. Suppose, a = 5 then, ++a; //a becomes 6 a++; //a becomes 7 --a; //a becomes 6 a--; //a becomes 5 Program: Difference between Prefix and Postfix notation void main () Output: { int i; the number is 0 i=0; the number is 1 printf(“the number is %d”, i); the number is 1 printf(“the number is %d”, ++i); the number is 0 printf(“the number is %d”, i); the number is 0 i=0; the number is 1 printf(“the number is %d”, i); printf(“the number is %d”, i++); printf(“the number is %d”, i); }
(Ebook) Papervision3D Essentials by Jeff Winder, Paul Tondeur ISBN 9781847195722, 1847195725 - Discover the ebook with all chapters in just a few seconds