🎙 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 4 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
int run(int argc, char *argv[]) {
    int total = 0;
    for (int i = 1; i < argc; i++)
        total += argv[i][0] - '0';
    return total;
}
int main(void) {
    char *v[] = {"./t", "3", "4", "5", NULL};
    printf("%d", run(4, v));
    return 0;
}
  1. A.15
  2. B.12
  3. C.7
  4. D.345
Answer & explanation

Correct answer: 12

The loop starts at 1, so it skips "./t" and adds the digits 3 + 4 + 5 = 12.

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 →