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 1 of 4.
Shiny vn said:
1 decade ago
Here we need to understand that it is a recursive call of a function.
(main() is also a function so it exhibits all characteristics of a function, you can understand that by knowing declaration of a function.
<return type> <function> <arguments> <function body>).
Now comes STACK, space in stack is allocated when a function call is done, to save the location where it should return when statements in function are executed.
The function main() has a statement which is calling itself without any condition. So each time the function is called space is allocated in stack. So stack space is allocated until there is no space left.
(main() is also a function so it exhibits all characteristics of a function, you can understand that by knowing declaration of a function.
<return type> <function> <arguments> <function body>).
Now comes STACK, space in stack is allocated when a function call is done, to save the location where it should return when statements in function are executed.
The function main() has a statement which is calling itself without any condition. So each time the function is called space is allocated in stack. So stack space is allocated until there is no space left.
(2)
Nath said:
4 years ago
I Think. Here we have to put a base case in function which is called, then only we could get an answer stack overflow. But here in this code, no base case is added so, the answer should be infinite times.
(1)
Dhiranjan mondal said:
5 years ago
infinite times is the correct answer.
(1)
Ammu said:
8 years ago
When will the answer becomes infinite times instead of stack overflow?
(1)
Rajesh said:
9 years ago
Anybody explain it, I am in little bit in confusion.
(1)
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.
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;
}
Kavitha said:
7 years ago
Thank you all for explaining this.
Bhavadip Gothadiya BG said:
8 years ago
#include<...> // it syntax is used for when Attached the header file into our program
#include" ... " //it syntax is used when we attached the user-defined header file with our program.
Similarly, it both are same
but it Uniquely identify the User-defined header file and inbuilt in Cpp or C compiler Header file.
#include" ... " //it syntax is used when we attached the user-defined header file with our program.
Similarly, it both are same
but it Uniquely identify the User-defined header file and inbuilt in Cpp or C compiler Header file.
Ashish kumar said:
8 years ago
What gives the programme if int main replaces the void main?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers