Exercise: Command Line Arguments

Questions for: Command Line Arguments

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: B
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>.
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: B
No answer description is available. Let's discuss.
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: C
No answer description is available. Let's discuss.
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: A
No answer description is available. Let's discuss.
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: C
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz