Discussion
Predict the output of below code:
#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: B
Correct answer: 3, 2, 15
Starting from a = {5, 1, 15, 20, 25}:
i = ++a[1];- pre-increment, soa[1]becomes 2 and i = 2.j = a[1]++;- post-increment, so j = 2 (the old value) anda[1]becomes 3.m = a[i++];- the subscript is the oldi, so m = a[2] = 15, andibecomes 3.
Printed: 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