C Programming - Command Line Arguments
Exercise : Command Line Arguments - Find Output of Program
- Command Line Arguments - General Questions
- Command Line Arguments - Find Output of Program
- Command Line Arguments - Point Out Correct Statements
- Command Line Arguments - True / False Questions
- Command Line Arguments - Yes / No Questions
6.
What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample "*.c"
cmd> sample "*.c"
/* sample.c */
#include<stdio.h>
int main(int argc, int *argv)
{
int i;
for(i=1; i<argc; i++)
printf("%s\n", argv[i]);
return 0;
}
7.
What will be the output of the program if it is executed like below?
cmd> sample
cmd> sample
/* sample.c */
#include<stdio.h>
int main(int argc, char **argv)
{
printf("%s\n", argv[argc-1]);
return 0;
}
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
cmd> sample friday tuesday sunday
/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%c", **++argv);
return 0;
}
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;
}
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;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers