C Programming - Command Line Arguments

6. 

What will be the output of the program (sample.c) given below if it is executed from the command line?
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;
}

A. *.c
B. "*.c"
C. sample *.c
D. List of all files and folders in the current directory

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.

7. 

What will be the output of the program if it is executed like below?
cmd> sample

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

int main(int argc, char **argv)
{
    printf("%s\n", argv[argc-1]);
    return 0;
}

A. 0
B. sample
C. samp
D. No output

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.

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

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

int main(int argc, char *argv[])
{
    printf("%c", **++argv);
    return 0;
}

A. s
B. f
C. sample
D. friday

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.

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

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

int main(int argc, char *argv[])
{
    printf("%c", *++argv[1]);
    return 0;
}

A. r
B. f
C. m
D. y

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.

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

/* 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;
}

A. three two one
B. owt
C. eno
D. eerht

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.