Machine-translated by Google. Questions are authored in English.
Top

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;
    }

 

  • A.1
  • B.Depends on the platform
  • C.Depends on the compiler

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.