Discussion
What will be the output of the program ?
#include <stdio.h>
int main()
{
char str[] = "peace";
char *s = str;
printf("%s\n", s++ +3);
return 0;
}
Answer: D
Correct answer: ce
The expression s++ +3 uses the original value of s, since ++ here is postfix, and adds 3 to it. s points at the start of "peace", so the argument to printf addresses position 3.
Counting from zero - p, e, a, c - position 3 is the c, so the output is ce. The increment of s itself happens too, but s is never used again. The spacing in s++ +3 is necessary: s+++3 would tokenise differently.
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