C Programming - Command Line Arguments - Discussion

Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 5)
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.
Discussion:
28 comments Page 2 of 3.

Vasu said:   9 years ago
argc is 1 because default takes one command line argument that is a.out, a.out is one file.

Rishi said:   1 decade ago
Why only argc as 1? I can always take 2 or 3, then the answer will vary right.

Ashok said:   10 years ago
But void function can't be to return any values how is this work?

Divya said:   8 years ago
Because main() is also a function where the program will start.

Merlin said:   1 decade ago
Thanks sreepal, your explanation is easy to understand.

Shreyaskar Nath said:   8 years ago
Answer will be 2, 3, 4. Option C is the correct one.

Arvind kumar said:   1 decade ago
Please explain it again to make more clear it. !

Sheetal said:   9 years ago
It is showing the answer as 2 3 4 in turbo C.

Dilip said:   8 years ago
But how we can call main from other function?

Aseem said:   1 decade ago
Thanks for this "cool" explanation :-)


Post your comments here:

Your comments will be displayed after verification.