C Programming - Command Line Arguments - Discussion

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

int main(int argc, char *argv[])
{
    printf("%s\n", argv[0]);
    return 0;
}
sample 3 2 3
sample 1 2 3
sample
Error
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
14 comments Page 2 of 2.

Shivu said:   1 decade ago
Please tell me why sample 123 wrong.

Anshi said:   1 decade ago
Please. If some one know it then explain it.

Nandhakumar said:   1 decade ago
Argv[0]=sample, no matter how many times you are called all are got overwritting.

Aman said:   1 decade ago
Can any one explane please?


Post your comments here:

Your comments will be displayed after verification.