← Quiz: Command-Line Arguments in C: all 10 questions
Quiz: Command-Line Arguments in C · Question 9 of 10
Which test correctly checks whether the first argument is the flag -v?
Which test correctly checks whether the first argument is the flag -v?
- A.if (argv[1] == "-v")
- B.if (argv[0] == "-v")
- C.if (argc > 1 && strcmp(argv[1], "-v") == 0)
- D.if (strcmp(argv, "-v"))
Answer & explanation
Correct answer: if (argc > 1 && strcmp(argv[1], "-v") == 0)
Check argc first, and compare string contents with strcmp, not ==.
Can you get the rest right without peeking?
Take the timed Quiz: Command-Line Arguments in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →