🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.if (argv[1] == "-v")
  2. B.if (argv[0] == "-v")
  3. C.if (argc > 1 && strcmp(argv[1], "-v") == 0)
  4. 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 →