Discussion
What will be the output of the program ?
#include <stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
Answer: C
Correct answer: 3, 2, 15
Take the three statements in order, starting from a = {5, 1, 15, 20, 25}.
i = ++a[1];- pre-increment:a[1]becomes 2 and that new value is assigned, so i = 2.j = a[1]++;- post-increment: j = 2 (the old value), anda[1]becomes 3.m = a[i++];- the subscript is the oldi, som = a[2] = 15, andithen becomes 3.
The printed values are therefore 3, 2, 15.
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