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;
}
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.
*maxptr = ++**mptr % **nptr;-++**mptrtakesmaxto 124, and \(124 \bmod 10 = 4\), somaxbecomes 4.max -= (*minptr - **nptr && *maxptr || *minptr);-10 - 10is 0, so the&&is 0;0 || 10is 1. Somaxbecomes 3.printf("%d %d", ++**mptr, *minptr);- the increment takesmaxback to 4, andminwas 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.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development