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 C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering 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 > Find Output of Program - Discussion

21. 

What will be the output of the program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int i=0;
    i++;
    if(i<=5)
    {
        printf("IndiaBIX");
        exit(1);
        main();
    }
    return 0;
}

[A]. Prints "IndiaBIX" 5 times
[B]. Function main() doesn't calls itself
[C]. Infinite loop
[D]. Prints "IndiaBIx"

Answer: Option A

Explanation:

Step 1: int i=0; The variable i is declared as in integer type and initialized to '0'(zero).

Step 2: i++; Here variable i is increemented by 1. Hence i becomes '1'(one).

Step 3: if(i<=5) becomes if(1 <=5). Hence the if condition is satisfied and it enter into if block statements.

Step 4: printf("IndiaBIX"); It prints "IndiaBIX".

Step 5: exit(1); This exit statement terminates the program execution.

Hence the output is "IndiaBIx".


Sneha said: (Fri, Sep 2, 2011 10:46:25 PM)    
 
What happens when it encounters main again in the program? It doesnt print back the same printf statement?

Ivo said: (Sun, Jun 3, 2012 01:45:32 AM)    
 
"IndiaBIX" is not the same as "IndiaBIx".
@Sneha: It would call main recursively until the stack overflows

Leszek said: (Sat, Jun 9, 2012 09:32:27 PM)    
 
Isn't B also correct? Maybe main() COULD call itself, but in this case it doesn't because it never gets to that point.

Prerna said: (Thu, Aug 9, 2012 12:34:56 AM)    
 
What would be the answer if it would have been exit(0) instead of exit(1).

Write your comments here:
Name *:     Email:


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

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