Increment Operator

Information about Increment Operator

Published on August 6, 2014

Author: sivasinstitute

Source: authorstream.com

Content

Increment Operator: Increment Operator Increment operator is used to increment the current value of variable by adding integer 1. It is one of the Unary Operator . Unary Operators require only one operand. Increment operator can be applied to only variables . Increment operator is denoted by ++. PowerPoint Presentation: Increment Operators are divided into two types ++(increment) pre post i.e. ++a a ++ PowerPoint Presentation: Pre-Increment: Pre-increment operator is used to increment the value of variable before using in the expression. In the Pre-Increment value is first incremented and then used inside the expression. Eg: ++a; here a=2 then a=3 Eg: a=1 ++a; 2 a; 2 ++a; 3 a; 3 PowerPoint Presentation: Example Program in C : m ain() { int a=1,b=0; clrscr(); b=++a; printf(“a=%d“,a); printf(“b=%d“,b); getch(); } Output: a=2 b=2 PowerPoint Presentation: Post-increment : Post-increment operator is used to increment the value of variable as soon as after executing expression completely in which post increment is used. In the Post-Increment value is first used in a expression and then incremented . Eg: a++; here a=2 then a=2 Eg: a=1 a++; 1 a; 2 a++; 2 a; 3 PowerPoint Presentation: Example Program in C : main() { int a=1,b=0; clrscr(); b=a++; printf(“a=%d“,a); printf(“b=%d“,b); getch(); } Output: a=2 b=1

Related presentations