Discussion
What will be the output of the program ?
#include <stdio.h>
int main()
{
static char s[25] = "The cocaine man";
int i=0;
char ch;
ch = s[++i];
printf("%c", ch);
ch = s[i++];
printf("%c", ch);
ch = i++[s];
printf("%c", ch);
ch = ++i[s];
printf("%c", ch);
return 0;
}
Answer: A
Correct answer: hhe!
Take the four statements in turn, with s = "The cocaine man" and i = 0.
s[++i]-ibecomes 1 first, so this iss[1]= h.s[i++]- the oldi, still 1, so h again;ibecomes 2.i++[s]- the same ass[i++], sos[2]= e;ibecomes 3.++i[s]- subscript binds tighter than the prefix++, so this increments the characters[3], a space (32), to 33 = !.
Output: hhe!
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