Discussion
What will be the output of the program if it is executed like below?
cmd> sample
/* sample.c */
#include <stdio.h>
int main(int argc, char **argv)
{
printf("%s\n", argv[argc-1]);
return 0;
}
Answer: A
Correct answer: sample
argv[0] is the program name as invoked, and with no further arguments argc is 1 - so argv[argc-1] is argv[0], which prints sample. The array always has argc entries plus a null pointer at argv[argc].
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