What is the output of the following ‘C’ language statements? #include…

2023

What is the output of the following ‘C’ language statements? #include <stdio.h> int main() { int a = 10, b = 20, *p1 = &a, *p2 = &b; printf("Before : **p1=%d **p2=%d", *p1, *p2); *p1 = *p1 + *p2; *p2 = *p1 - *p2; *p1 = *p1 - *p2; printf("\nAfter : **p1=%d **p2=%d", *p1, *p2); return 0; }

Attempted by 359 students.

Show answer & explanation

Step 1: Initialize variables: a = 10, b = 20, *p1 = &a, *p2 = &b. So, *p1 = 10, *p2 = 20.

Step 2: *p1 = *p1 + *p2 → *p1 = 10 + 20 = 30.

Step 3: *p2 = *p1 - *p2 → *p2 = 30 - 20 = 10.

Step 4: *p1 = *p1 - *p2 → *p1 = 30 - 10 = 20.

Final values: *p1 = 20, *p2 = 10.

Explore the full course: Up Lt Grade Assistant Teacher 2025