Whether there can be main inside another main?If so how does
it work?
Answers were Sorted based on User's Feedback
Answer / namita
main()
{
main();
}
This code snippet will result in infinite loop.
| Is This Answer Correct ? | 43 Yes | 15 No |
Answer / divyansh
main marks the beginning of a program, 2 direct mains can't
be there as it will make the compiler dumb!(literally),in
this case it will give an error, or an infinite loop
operation will be executed.
| Is This Answer Correct ? | 21 Yes | 3 No |
Answer / nilanjan
Surely. . It will just act like a recursive version of
main(), which will run infinite times if there is no
limiting condition specified.
Sample:
#include <stdio.h>
int main()
{
int static i = 0;
printf("\nFile is too big.");
while(i == 0)
{
i++;
main();
}
return 0;
}
| Is This Answer Correct ? | 21 Yes | 3 No |
Answer / vara
there will be no error but the output will go in infinite
loop
main()
{
int a=2,b=3;
a=a+b;
b=a-b;
a=a-b;
printf("%d",&a);
printf("%d",&b);
main();
getch();
}
| Is This Answer Correct ? | 19 Yes | 5 No |
Answer / rajdesai143
yes.There can be any no of main inside the main.But one
static main should be required .In that we can call any no
of times it just works as recursive.
Since one static main is required because (astart) requires
that . Its a startup code
| Is This Answer Correct ? | 9 Yes | 0 No |
Answer / gprabha
#include<stdio.h>
void main()
{
printf("main()");
main();
getch();
}
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / harinath
yes there can be
for example
main()
{
static int count=50;
printf("%d",count--);
while(count>0)
main();
}
here the output is numbers upto 1 then it comes out of it.
| Is This Answer Correct ? | 1 Yes | 1 No |
What is use of bit field?
I came across some code that puts a (void) cast before each call to printf. Why?
Predict the output or error(s) for the following: 25. main() { printf("%p",main); }
Is c compiled or interpreted?
What is const keyword in c?
How many loops are there in c?
What is pointers in c with example?
what is the definition of storage classes?
what is the output of the following program and explain the answer #include<stdio.h> exp() { main(5) } main(int a) { printf("%d",a); return; }
What is main () in c language?
write a program to print largest number of each row of a 2D array
What is diffrance between declaration and defination of a variable or function