LearnFrenzy
Sign in Take a free test

Command Line Arguments · Predict the Output · Question 12

*(argv + 2) and **(argv + 1) – output Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What is the output of the following C program when it is run as shown?

Run as: ./app alpha beta

main.c
#include <stdio.h>

int main(int argc, char **argv) {
    if (argc != 3)
        return 1;
    printf("%s %c\n", *(argv + 2), **(argv + 1));
    return 0;
}
  • A alpha b
  • B beta b
  • C beta a Correct
  • D alpha a
Correct Answer: Option C

*(argv + 2) is argv[2], the string "beta". **(argv + 1) is argv[1][0], the first character of "alpha".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links