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 3 of 4.
Shiny vn said:
1 decade ago
Its a C program you may try by using some other or can try with terminals.
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)
Rajesh said:
9 years ago
Anybody explain it, I am in little bit in confusion.
(1)
Benito said:
8 years ago
Thank you all for the given explanation.
Ammu said:
8 years ago
When will the answer becomes infinite times instead of stack overflow?
(1)
Ashish kumar said:
8 years ago
What gives the programme if int main replaces the void main?
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.
Kavitha said:
7 years ago
Thank you all for explaining this.
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;
}
Dhiranjan mondal said:
5 years ago
infinite times is the correct answer.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers