C Programming - Functions - Discussion
Discussion Forum : Functions - General Questions (Q.No. 3)
3.
How many times the program will print "IndiaBIX" ?
#include<stdio.h>
int main()
{
printf("IndiaBIX");
main();
return 0;
}
Answer: Option
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.
Discussion:
31 comments Page 2 of 4.
DK SINGH said:
1 decade ago
Return 0 and 1 these are function return type. If function does not return anything then it return 0.
Ex: If int main then it return by default 0. And void main is by default 1.
Ex: If int main then it return by default 0. And void main is by default 1.
Ramesh Vetsa said:
1 decade ago
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:
1 decade ago
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;
}
Please tell me. if any one
ex:-
int main()
{
printf("hello");
return 0;
}
Anumita Singha Roy said:
1 decade ago
@Ivo.
Can you explain what do you mean by the sentence "An infinite loop is when we have for example while(1) , where nothing is added to the stack. ".
Can you explain what do you mean by the sentence "An infinite loop is when we have for example while(1) , where nothing is added to the stack. ".
Mini said:
1 decade ago
When I run this code on online compiler its gave me this output.
"The output size is too large (infinite loop or larger text output)".
"The output size is too large (infinite loop or larger text output)".
Teja said:
7 years ago
@All.
Predict the Output of the program.
#include<stdio.h>
int main()
{
int var=0x43FF;
printf("%d",var);
return 0;
}
Predict the Output of the program.
#include<stdio.h>
int main()
{
int var=0x43FF;
printf("%d",var);
return 0;
}
Kavin said:
1 decade ago
int main()
{
printf("hello");
main();
return 0;
}
It will show the abnormal program termination message in turbo C++ 4.0 compiler.
{
printf("hello");
main();
return 0;
}
It will show the abnormal program termination message in turbo C++ 4.0 compiler.
Rakesh said:
1 decade ago
In this program you gave main() recursively and it will be print up to infinite times.Is it correct?or not?
Sandy said:
1 decade ago
Can anybody tell how much amount of stack memory is allocated and upon which this depends?
Ram said:
1 decade ago
We can call main function with in a main function and in this we have " ; " how?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers