IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C# Programming Java Programming
Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Functions - Discussion

@ : Home > C Programming > Functions > General Questions - Discussion

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.


Sandy said: (Tue, Feb 8, 2011 07:24:15 AM)    
 
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"

Write your comments here:
Name *:     Email:


© 2008-2011 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Advertise     Contact us: info@indiabix.com     Follow us on twitter!