C Programming - Command Line Arguments

1.
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)
{
    printf("%c\n", **++argv);
    return 0;
}
myprog one two three
myprog one
o
two
Answer: Option
Explanation:
No answer description is available. Let's discuss.

2.
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>
#include<stdlib.h>

int main(int argc, char **argv)
{
    printf("%s\n", *++argv);
    return 0;
}
myprog
one
two
three
Answer: Option
Explanation:
No answer description is available. Let's discuss.

3.
What will be the output of the program (sample.c) given below if it is executed from the command line (Turbo C in DOS)?
cmd> sample 1 2 3
/* sample.c */
#include<stdio.h>

int main(int argc, char *argv[])
{
    int j;
    j = argv[1] + argv[2] + argv[3];
    printf("%d", j);
    return 0;
}
6
sample 6
Error
Garbage value
Answer: Option
Explanation:

Here argv[1], argv[2] and argv[3] are string type. We have to convert the string to integer type before perform arithmetic operation.

Example: j = atoi(argv[1]) + atoi(argv[2]) + atoi(argv[3]);


4.
What will be the output of the program (sample.c) given below if it is executed from the command line (turbo c under DOS)?
cmd> sample Good Morning
/* sample.c */
#include<stdio.h>

int main(int argc, char *argv[])
{
    printf("%d %s", argc, argv[1]);
    return 0;
}
3 Good
2 Good
Good Morning
3 Morning
Answer: Option
Explanation:
No answer description is available. Let's discuss.

5.
What will be the output of the program
#include<stdio.h>
void fun(int);

int main(int argc)
{
    printf("%d ", argc);
    fun(argc);
    return 0;
}
void fun(int i)
{
    if(i!=4)
        main(++i);
}
1 2 3
1 2 3 4
2 3 4
1
Answer: Option
Explanation:
No answer description is available. Let's discuss.