Discussion
What will be the output of the following C code (if run with no options or arguments)?
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%d\n", argc);
return 0;
}
Answer: A
Correct answer: 1
Run with no options or arguments, argc is 1: the program name in argv[0] is itself counted.
The value is not platform-dependent in any practical sense - the standard requires the program name to be represented and counted when it is available - so the second and third options fail. The single theoretical exception is a program started by an exec call passing no name at all, which gives argc of 0, and no shell does that.
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