"No one is as deaf as the man who will not listen."
- (Proverb)
3.
How many times the program will print "IndiaBIX" ?
#include<stdio.h>
int main()
{
printf("IndiaBIX");
main();
return 0;
}
[A].
Infinite times
[B].
32767 times
[C].
65535 times
[D].
Till stack doesn't overflow
Answer: Option B
Explanation:
A call stack or function stack is used for several related purposes, but the main reason for having one is to keep track of the point to which each active subroutine should return control when it finishes executing.
A stack overflow occurs when too much memory is used on the call stack.
Here function main() is called repeatedly and its return address is stored in the stack. After stack memory is full. It shows stack overflow error.
Can anybody tell how much amount of stack memory is allocated and upon which this depends?
Sanket said:
(Thu, Mar 10, 2011 05:13:06 AM)
I tried this program on Turbo C++ 4.5 compiler and it gives me error "Cannot call 'main' from within the program in function main()
Also where we used stack here??
Does stack refers to 'Main Memory'?
Ramesh Vetsa said:
(Sat, Jun 25, 2011 12:06:57 AM)
In the above program we are just printing the statement. we are not declaring any variables and not using any memory. Then why it runs up till stack doesn't overflow?
Kuldeep Chaudhary said:
(Fri, Aug 26, 2011 06:46:34 PM)
What is the meaning of return 0 or return 1 in main() function body?
Please tell me. if any one
ex:-
int main()
{
printf("hello");
return 0;
}
Kuldeep Chaudhary said:
(Fri, Aug 26, 2011 06:48:59 PM)
What is the diff b/w
#include"...."
and
#include<....>
Dnyaneshwar said:
(Tue, Sep 20, 2011 11:23:12 PM)
@Kuldeep Chaudhary
Every called function return value to it's calling function.
Here main() function called by operating system that is main() is called fun and o.s. is calling.
Called fun return 0 after successful execution of program.
If there is any error in execution then it return any nonzero value to it's caller. That value may be +ve or -ve.
Rakesh said:
(Tue, Oct 25, 2011 10:26:19 PM)
In this program you gave main() recursively and it will be print up to infinite times.Is it correct?or not?
Jeff Mccracken said:
(Mon, Jan 23, 2012 03:15:31 AM)
I think answer D should state "Until the stack DOES overflow"