C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 9)
9.
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
cmd> myprog friday tuesday sunday
/* myprog.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%c", *++argv[1]);
return 0;
}
Discussion:
12 comments Page 2 of 2.
Sunitha said:
1 decade ago
argc converts first string datatype to integer hence the string myprog converted to integer and argc reads no of arguments that passed assigneed that values to argv hence pointer points to to string friday's first character and its get incremented and points to r.
Vishal kumbhar said:
1 decade ago
Guys,
argv[1] means "friay"
++arv[1] means "r"
it prints "r".
ok
argv[1] means "friay"
++arv[1] means "r"
it prints "r".
ok
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers