C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 19)
19.
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
cmd> sample friday tuesday sunday
/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%c", *++argv[2] );
return 0;
}
Discussion:
25 comments Page 2 of 3.
Pankaj kumar singh said:
1 decade ago
The answer is you but, I the explanation is not correct because sample is prog name and the arguments are friday[0] tuesday[1] and sunday[2] so you belongs from sunday.
Priyanka said:
7 years ago
In C;
argv[1]=sample
argv[2]=friday
argv[3]=tuesday
So, in Q *++argv[2] so argv[2] is f but after increment next char which is r.
argv[1]=sample
argv[2]=friday
argv[3]=tuesday
So, in Q *++argv[2] so argv[2] is f but after increment next char which is r.
Nikhil said:
8 years ago
I have doubt @Sushma how you take this value can you explain?
argv[0]=sample
argv[1]=friday
argv[2]=tuesday
argv[0]=sample
argv[1]=friday
argv[2]=tuesday
Balaji said:
1 decade ago
@Sumit: It will print null('\0') character. i.e. blank space will be printed.
Manjunath(mj) said:
10 years ago
This will print s.
How it will print u friends please any one explain me?
How it will print u friends please any one explain me?
Sumit said:
1 decade ago
in *++argv[2]
argv[0]=t
argv[1]=u
argv[2]=e
Then whats is the answer.
argv[0]=t
argv[1]=u
argv[2]=e
Then whats is the answer.
Mohamed said:
8 years ago
I think argv[0] always contains the name of the program? isn't it?
Alok said:
1 decade ago
Can anybody explain ? How it's(*++argv[2]) pointing to 'U' ?
Sundar said:
1 decade ago
@Sushma
Exactly. Thanks for your explanation.
Exactly. Thanks for your explanation.
Yugandhar said:
1 decade ago
Your explanation is gud, thank you.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers