C Programming - Command Line Arguments - Discussion

Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 8)
8.
What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample friday tuesday sunday
/* sample.c */
#include<stdio.h>

int main(int argc, char *argv[])
{
    printf("%c", **++argv);
    return 0;
}
s
f
sample
friday
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
17 comments Page 2 of 2.

Bhimeswar said:   1 decade ago
Here in main brackets we write chaar *argv[] so the base address goes to*argv[0]if we inrcrement second string address is *argv[1]

**argv[1] means string but in printf we wrote %c only so it displays first character f.

Rookie said:   1 decade ago
As said by Shanmugam, argv indicates argv[0].++argv points to argv[1]...now *argv[1] is a pointer to second argument vector.

**argv[1] contains the value "friday".But as we are printing "%c",

we get only the first character. i.e. "f".. thats why the ans.

Lakshmi said:   1 decade ago
Its not clear.

Manish said:   1 decade ago
I still could not get understood yet. Please further explain.

Shanmugam said:   1 decade ago
argv[0] = "sample";
argv[1] = "friday";
argv[2] = "thuesday";
argv[3] = "sunday";

argv indicates argv[0].so ++argv increments to the next 1-D array.so it points argv[1].Then **argv[1] is points 'f'.

Sugimalathi said:   1 decade ago
Explain this answer please.

Hariom said:   1 decade ago
Can't understand logic, please help me to undestnd the logic behind it.

I can't understand the roll of dpuble pointer.


Post your comments here:

Your comments will be displayed after verification.