Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of the following program?

#include <stdio.h>
int main()
{
int max =123, min = 10, *maxptr = &max, *minptr = &min;
int **nptr = &minptr, **mptr = &maxptr;
*maxptr = ++**mptr % **nptr;
max -= ( *minptr - **nptr && *maxptr || *minptr);
printf( " %d %d", ++**mptr, *minptr);
return 0;
}

 

  • A.4 10
  • B.3 11
  • C.3 10
  • D.4 11

Answer: A

Correct answer: 4 10

Work through the pointers. maxptr points at max, minptr at min, and mptr and nptr point at those two pointers, so **mptr is max and **nptr is min.

  1. *maxptr = ++**mptr % **nptr; - ++**mptr takes max to 124, and \(124 \bmod 10 = 4\), so max becomes 4.
  2. max -= (*minptr - **nptr && *maxptr || *minptr); - 10 - 10 is 0, so the && is 0; 0 || 10 is 1. So max becomes 3.
  3. printf("%d %d", ++**mptr, *minptr); - the increment takes max back to 4, and min was never touched, so it is 10.

Output: 4 10.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.