← Quiz: Command-Line Arguments in C: all 10 questions
Quiz: Command-Line Arguments in C · Question 10 of 10
What does this print? (code)
What does this print?
#include <stdio.h>
#include <string.h>
int run(int argc, char *argv[]) {
int count = 0;
for (int i = 1; i < argc; i++)
if (argv[i][0] == '-') count++;
return count;
}
int main(void) {
char *v[] = {"./ls", "-l", "docs", "-a", "-", NULL};
printf("%d", run(5, v));
return 0;
}
- A.2
- B.3
- C.4
- D.1
Answer & explanation
Correct answer: 3
"-l", "-a" and "-" all start with '-'; "./ls" is skipped because the loop starts at 1.
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 →