← Quiz: Command-Line Arguments in C: all 10 questions
Quiz: Command-Line Arguments in C · Question 6 of 10
A program uses argv[1] without checking argc and is run with no arguments. What happens?
A program uses argv[1] without checking argc and is run with no arguments. What happens?
- A.argv[1] is an empty string, so it works
- B.The compiler reports an error
- C.argv[1] is NULL, so using it as a string is undefined behaviour and usually crashes
- D.The program asks for input
Answer & explanation
Correct answer: argv[1] is NULL, so using it as a string is undefined behaviour and usually crashes
With no arguments, argc is 1 and argv[1] is the NULL that ends the array.
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 →