Find Output Of Program

Question 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;
}


A). List of all environment variables
B). List of all command-line arguments
C). count of command-line arguments
D). Error: cannot have more than two arguments in main()
Answer : Option A

Question 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

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


A). No output
B). sample Jan Feb Mar
C). Jan Feb Mar
D). Error
Answer : Option C

Question 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

/* sample.c */
#include < stdio . h >
int main(int argc, char *argv[])
{
    while(--argc>0)
        printf("%s", *++argv);
    return 0;
}


A). sample monday tuesday wednesday thursday
B). monday tuesday wednesday thursday
C). monday tuesday thursday
D). tuesday
Answer : Option B

Question 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;
}


A). SAMPLE.C
B). C:\TC\MYPROC.EXE
C). C:\TC
D). Error
Answer : Option B

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 .


Question 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

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


A). oot
B). ott
C). nwh
D). eoe
Answer : Option B