What is the output in a 32 bit machine with 32 bit compiler ? C#include…

2020

What is the output in a 32 bit machine with 32 bit compiler ?

C
#include <stdio.h>

rer(int **ptr2, int **ptr1)
 {
  int* ii;
  ii = *ptr2;
  *ptr2 = *ptr1;
  *ptr1 = ii;
  **ptr1 *= **ptr2;
  **ptr2 += **ptr1;
 }
void main( )
 {
   int var1 = 5, var2 = 10;
   int *ptr1 = &var1, *ptr2 = &var2;
   rer(&ptr1, &ptr2);
   printf(“%d %d “, var2, var1);
 } 
  1. A.

    60 70

  2. B.

    50 50

  3. C.

    50 60

  4. D.

    60 50

Attempted by 207 students.

Show answer & explanation

Correct answer: D

Initially, var1 = 5 and var2 = 10. Pointers ptr1 points to var1, and ptr2 points to var2.

In rer, parameters are defined as (ptr2, ptr1) but called with (&ptr1, &ptr2). This swaps the mapping inside the function.

The function swaps the addresses stored in main's pointers. After swapping, local **ptr1 accesses var1 and local **ptr2 accesses var2.

Calculations update var1 to 50 (5 * 10) and var2 to 60 (10 + 50). The output prints var2 then var1.

Final Output: 60 50

Explore the full course: Isro