Write a program to show the effect of increment operator as a suffix.

c
#include<stdio.h>
#include<conio.h>
main()
{
	int a,z,x=10,y=30;
	z=x*y++;      //++ after y is called suffix//
	a=x*y;
	printf("\n %d %d",z,a);
	getch();
}



/*y does not get incremented,After Y incremented to 31.
second equation give the result 310.*/

The above program demonstrates the difference between post-increment and pre-increment operators. The post-increment operator increments the value of the operand after it has been used in the expression. In the example, y++ increments the value of y to 31 after it has been used in the first expression to calculate z. In the second expression, x * y calculates the result of x * 31 as 310.

Thanks

Write a program to show the effect of increment operator as a suffix.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top