0% found this document useful (0 votes)
5 views2 pages

Program Explanation

Uploaded by

aishik130811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Program Explanation

Uploaded by

aishik130811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Program Explanation

#include <stdio.h>

int main() {
int x = 10, y = 20;
int result;

printf("Original values, x = %d and y = %d\n", x, y);

// Pre-increment
result = ++x;
printf("After pre-incrementing, x = %d and result = %d\n", x,
result);

// Post-increment
result = y++;
printf("After post-incrementing, y = %d and result = %d\n", y,
result);

// Pre-decrement
result = --x;
printf("After pre-decrementing, x = %d and result = %d\n", x,
result);

// Post-decrement
result = y--;
printf("After post-decrementing, y = %d and result = %d\n", y,
result);

return 0;
}

Explanation of Each Step:


1. Initial Values:

int x = 10, y = 20;


 x is initialized to 10.
 y is initialized to 20.
The first printf prints the original values of x and y:

Original values, x = 10 and y = 20


2. Pre-Increment:

result = ++x;
 Pre-increment means the value of x is incremented first, and then
the incremented value is assigned to result.
 So, x is incremented from 10 to 11.
 result is assigned the value of x, which is now 11.
The second printf prints:
After pre-incrementing, x = 11 and result = 11

3. Post-Increment:
result = y++;
 Post-increment means the value of y is assigned to result first, and
then y is incremented.
 result is assigned the value of y, which is 20 (the current value of y).
 Then, y is incremented from 20 to 21.
The third printf prints:
After post-incrementing, y = 21 and result = 20

4. Pre-Decrement:
result = --x;
 Pre-decrement means the value of x is decremented first, and then
the decremented value is assigned to result.
 So, x is decremented from 11 to 10.
 result is assigned the value of x, which is now 10.
The fourth printf prints:
After pre-decrementing, x = 10 and result = 10

5. Post-Decrement:
result = y--;
 Post-decrement means the value of y is assigned to result first, and
then y is decremented.
 result is assigned the value of y, which is 21 (the current value of y).
 Then, y is decremented from 21 to 20.
The fifth printf prints:
After post-decrementing, y = 20 and result = 21

Final Output:
The complete output of this program will be:

Original values, x = 10 and y = 20


After pre-incrementing, x = 11 and result = 11
After post-incrementing, y = 21 and result = 20
After pre-decrementing, x = 10 and result = 10
After post-decrementing, y = 20 and result = 21

You might also like