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
11.
What will be the output of the program in Turbo C?
#include<stdio.h>
int main(int argc, char *argv, char *env[])
{
int i;
for(i=1; i<argc; i++)
printf("%s\n", env[i]);
return 0;
}
12.
What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample Jan Feb Mar
cmd> sample Jan Feb Mar
/* sample.c */
#include<stdio.h>
#include<dos.h>
int main(int arc, char *arv[])
{
int i;
for(i=1; i<_argc; i++)
printf("%s ", _argv[i]);
return 0;
}
13.
What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample monday tuesday wednesday thursday
cmd> sample monday tuesday wednesday thursday
/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
while(--argc>0)
printf("%s", *++argv);
return 0;
}
14.
If the following program (myproc.c) is present in the directory "C:\TC" then what will be output of the program if run it from DOS shell?
/* myproc.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%s", argv[0]);
return 0;
}
Answer: Option
Explanation:
In order to execute it from DOS shell, we have to run the created EXE file by entering the exe file name as C:\TC>myproc <enter>.
15.
What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog one two three
cmd> myprog one two three
/* myprog.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
int i;
for(i=1; i<argc; i++)
printf("%c", argv[i][0]);
return 0;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers