Pages

Showing posts with label PRE INCREMENT AND POST INCREMENT IN C. Show all posts
Showing posts with label PRE INCREMENT AND POST INCREMENT IN C. Show all posts

Friday, July 31, 2020

PRE INCREMENT AND POST INCREMENT IN C

PRE INCREMENT
Pre increment operator is used to increment the value of a variable before using that variable in a syntax.

EXAMPLE
In the below example 'a' is a variable name and Pre-increment (++)  operator adding 1 in the value of 'a' before executing the variable 'a', So the printf statement print 5 as the value of a variable.
void main()
{
int a=4;
printf(%d",++a); // Example of pre increment operator
getch();
}

- - - - - PROGRAM OUTPUT - - - - -
5
- - - - - - - - -- - - - - - - - - - - - - - - - - -

POST INCREMENT
Post increment operator is used to increment the value of a variable after execute that variable expression.

EXAMPLE
In the below example the Post-increment operator adding 1 in the value of  'a' variable after executing the variable in the printf statement, therefore the printf statement will print the 4 as output value.
void main()
{
int a=4;
printf(%d",a++); // Example of post increment operator
getch();
}

- - - - - PROGRAM OUTPUT - - - - -
4
- - - - - - - - -- - - - - - - - - - - - - - - - - -

WHILE LOOP >>