Whether there can be main inside another main?If so how does
it work?

Answers were Sorted based on User's Feedback



Whether there can be main inside another main?If so how does it work?..

Answer / namita

main()
{
main();
}

This code snippet will result in infinite loop.

Is This Answer Correct ?    43 Yes 15 No

Whether there can be main inside another main?If so how does it work?..

Answer / shiva

main()
{
printf("main()");
}

Is This Answer Correct ?    39 Yes 19 No

Whether there can be main inside another main?If so how does it work?..

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

Whether there can be main inside another main?If so how does it work?..

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

Whether there can be main inside another main?If so how does it work?..

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

Whether there can be main inside another main?If so how does it work?..

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

Whether there can be main inside another main?If so how does it work?..

Answer / kasthurimangai.v

main()
{
printf("main()");
}

Is This Answer Correct ?    8 Yes 3 No

Whether there can be main inside another main?If so how does it work?..

Answer / gprabha

#include<stdio.h>
void main()
{
printf("main()");
main();
getch();
}

Is This Answer Correct ?    3 Yes 1 No

Whether there can be main inside another main?If so how does it work?..

Answer / guest

nested main

Is This Answer Correct ?    1 Yes 0 No

Whether there can be main inside another main?If so how does it work?..

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

Post New Answer

More C Interview Questions

#define MAX 3 main() { printf("MAX = %d ",MAX ); #undef MAX #ifdef MAX printf("Vector Institute”); #endif }

1 Answers   Vector India,


What library is sizeof in c?

0 Answers  


Explain argument and its types.

0 Answers  


send me the code of flow chart generator using C-programming language amd this code should calculate the time and space complexity of the given progran and able to generate flowchart according to the given program?

0 Answers   TCS,


how to return 1000 variables from functio9n in c?plz give me code also

6 Answers  


identify the in correct expression a.a=b=3=4; b.a=b=c=d=0; float a=int b=3.5; d.int a; float b; a=b=3.5;

8 Answers   TCS,


What is the g value paradox?

0 Answers  


consider the following structure: struct num nam{ int no; char name[25]; }; struct num nam n1[]={{12,"Fred"},{15,"Martin"},{8,"Peter"},{11,Nicholas"}}; ..... ..... printf("%d%d",n1[2],no,(*(n1 + 2),no) + 1); What does the above statement print? a.8,9 b.9,9 c.8,8 d.8,unpredictable value

4 Answers   TCS,


regarding the scope of the varibles;identify the incorrect statement: a.automatic variables are automatically initialised to 0 b.static variables are are automatically initialised to 0 c.the address of a register variable is not accessiable d.static variables cannot be initialised with any expression

1 Answers   TCS,


In scanf h is used for

4 Answers   BFL,


consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is

4 Answers   TCS,


A C E G H +B D F A I ------------ E F G H D

1 Answers   Infosys,


Categories