C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 10)
10.
What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample one two three
cmd> sample one two three
/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
int i=0;
i+=strlen(argv[1]);
while(i>0)
{
printf("%c", argv[1][--i]);
}
return 0;
}
Discussion:
18 comments Page 2 of 2.
Pallavi said:
1 decade ago
In printf statement %c is used.
And if argv[1][--i]=argv[1][2]=e then i am expecting only 'e' to be printed as output then how option 'c' i.e 'eno' can be the answer?
And if argv[1][--i]=argv[1][2]=e then i am expecting only 'e' to be printed as output then how option 'c' i.e 'eno' can be the answer?
Siva said:
1 decade ago
@maris...small mistake
while(3>0)
argv[1][--i] .. its predecrement ..so argv[1][2]->e..and so on..
while(3>0)
argv[1][--i] .. its predecrement ..so argv[1][2]->e..and so on..
Nitin said:
1 decade ago
Can anybody Tell me How argument is passed in a main function ?
What this argv, *argv means.
What this argv, *argv means.
Dia gupta said:
8 years ago
Can anyone plz exp how i becomes 3?
i+=strlen(argv[1]) -> i BECOMES 3
i+=strlen(argv[1]) -> i BECOMES 3
Vishyy said:
1 decade ago
How does this program will execute. ?
Somebody please tell the process.
Somebody please tell the process.
Chandra said:
1 decade ago
@pallavi: While loop will be continue.
Deepak kumar said:
1 decade ago
How eno is output of the program?
Shruti said:
9 years ago
Can anyone explain it in detail?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers