It is used to check simple condition. It is a Special case of assignment operation,
associated with a conditional evaluation.
(Expression1) ? Expression2 : Expression3;
If Expression1 is evaluated to TRUE then Expression2 is considered.
If Expression1 is evaluated to FALSE then Expression3 is considered.
# include <stdio.h>
void main( )
Variable declaration with initialization,
using this style the garbage values are eliminated and makes variables to be more consistent in nature. This style of changing the original data from an existing variable is recognized as Updation Style.
int x = 0, R;
printf(“\nEnter value for x : ”);
scanf (“%d”, &x);
R = (x > 10) ? 15 : 20;
printf(“\nThe result R = %d”, R);
Auto Incrementation Operator(++)
Post Increment Mode
The value of the variable is assigned first.
Then the incrementation is followed.
x = y++
Step 1 : The original Value of y is assigned to x First.
Step 2 : Then the Value of y is incremented by 1.
int y = 6;
printf(“y = %d”, y++);
Pre Increment Mode:
The value of the original variable is incremented first.
Then the incremented value is assigned.
x = ++y;
Step 1 : Value of the y is incremented by 1 First.
Step 2 : Then the assignment to x is done.
void main( )
Here the original value of the y is assigned to the printf first and then the value of y is incremented by 1. Here the original value of the y is incrementd first and then the incremented value of y is assigned to printf.
printf (“y = %d”, ++y);