🎙 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 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;
}
  1. A.2
  2. B.3
  3. C.4
  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 →