Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog friday tuesday sunday

/* myprog.c */
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("%c", *++argv[1]);
    return 0;
}

 

  • A.r
  • B.f
  • C.m
  • D.y

Answer: A

Correct answer: r

Subscripting binds tighter than the prefix ++, so the expression is *(++(argv[1])). It is the pointer stored in argv[1] that is advanced, not argv.

argv[1] points at "friday"; advancing it by one character makes it point at the 'r', and the * yields that character. The contrast with **++argv, which gives 'f', is entirely a matter of which pointer the increment reaches.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.