Command Line Arguments

11

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

/* sample.c */
#include<stdio.h>

int main(int argc, char *argv[])
{
    printf("%c", *++argv[2] );
    return 0;
}
A. s
B. f
C. u
D. r

12

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

/* sample.c */
#include<stdio.h>

int main(int sizeofargv, char *argv[])
{
    while(sizeofargv)
        printf("%s", argv[--sizeofargv]);
    return 0;
}
A. sample friday tuesday sunday
B. sample friday tuesday
C. sunday tuesday friday sample
D. sunday tuesday friday

13

What will be the output of the program (sample.c) given below if it is executed from the command line? cmd> sample 1 2 3 cmd> sample 2 2 3 cmd> sample 3 2 3

/* sample.c */
#include<stdio.h>

int main(int argc, char *argv[])
{
    printf("%s\n", argv[0]);
    return 0;
}
A. sample 3 2 3
B. sample 1 2 3
C. sample
D. Error

14

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

/* myprog.c */
#include<stdio.h>

int main(int argc, char *argv[])
{
    int i;
    for(i=1; i
 
                                                    
A. oot
B. ott
C. nwh
D. eoe

15

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;
}
A. SAMPLE.C
B. C:TCMYPROC.EXE
C. C:TC
D. Error