Discussion
What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample friday tuesday sunday
/* sample.c */
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%c", **++argv);
return 0;
}
Answer: B
Correct answer: f
++argv advances the pointer to argv[1], so the first * gives the string "friday" and the second gives its first character, 'f'.
Compare with *++argv[1], which increments the pointer inside the array rather than the array pointer itself and yields 'r'. Which pointer moves is decided by precedence: subscripting binds tighter than the prefix ++, so ++argv[1] increments argv[1], while ++argv increments argv.
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