C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 5)
                   
                                       
                                5.
Which of the following statements are correct about the below program?
 
                                    #include<stdio.h>
int main()
{
    int i = 0;
    i++;
    if(i <= 5)
    {
        printf("IndiaBIX\n");
        exit(0);
        main();
    }
    return 0;
}
Answer: Option
                                                    Explanation:
                                                
Step 1: int i = 0; here variable i is declared as an integer type and initialized to '0'(zero).
Step 2: i++; here variable i is increemented by 1(one). Hence, i = 1
Step 3: if(i <= 5) becomes if(1 <= 5) here we are checking '1' is less than or equal to '5'. Hence the if condition is satisfied.
Step 4: printf("IndiaBIX\n"); It prints "IndiaBIX"
Step 5: exit(); terminates the program execution.
Hence the output is "IndiaBIX".
Discussion:
16 comments Page 1 of 2.
                
                        Pooja said: 
                         
                        8 years ago
                
                In function 'main':
Line 11: warning: incompatible implicit declaration of built-in function 'exit'.
Line 15: error: expected declaration or statement at end of input.
If we compile the programme given in question then it gives above error statements.
                Line 11: warning: incompatible implicit declaration of built-in function 'exit'.
Line 15: error: expected declaration or statement at end of input.
If we compile the programme given in question then it gives above error statements.
                        Poonam said: 
                         
                        1 decade ago
                
                Yes main can call itself
#include<stdio.h>
int i=0;
int main()
{
i++;
if(i <= 5)
{
printf("IndiaBIX\n");
main();
        
}
return 0;
}
o/p
IndiaBIX
IndiaBIX
IndiaBIX
IndiaBIX
IndiaBIX
                #include<stdio.h>
int i=0;
int main()
{
i++;
if(i <= 5)
{
printf("IndiaBIX\n");
main();
}
return 0;
}
o/p
IndiaBIX
IndiaBIX
IndiaBIX
IndiaBIX
IndiaBIX
                        Sathuragiri said: 
                         
                        1 decade ago
                
                This is simple. It will print indiabix one time because there will be conditional statement presented. Instead of that if there while or for (looping statements) presented means it will printed 5 times.
                
                        Keerthi said: 
                         
                        1 decade ago
                
                @Syam.
Nothing will happen when we remove the inside main() function,
Because exit(0) will terminate the program, so the printf statement will execute one time.
                Nothing will happen when we remove the inside main() function,
Because exit(0) will terminate the program, so the printf statement will execute one time.
                        Keerthi said: 
                         
                        1 decade ago
                
                @syam
nothing will happen when we remove the inside main()function,
because exit(0) will terminate the program,so the printf statement will execute one time
                nothing will happen when we remove the inside main()function,
because exit(0) will terminate the program,so the printf statement will execute one time
                        Jay prakash said: 
                         
                        1 decade ago
                
                B and C will be the correct options. As program terminates when exit(0) is called. So call to main() after exit() doesn't materialize.
                
                        Pooja said: 
                         
                        8 years ago
                
                Here, exit(0); requires <stdlib.h> included in file. Is'nt it?
as per this,it should give error.
                as per this,it should give error.
                     (1)
                
            
                        OMKAR said: 
                         
                        1 decade ago
                
                According to me,
Answer should be C as stdlib.h isn't included and it hence cannot be resolved;
                Answer should be C as stdlib.h isn't included and it hence cannot be resolved;
                        Pruthvi said: 
                         
                        1 decade ago
                
                Will exit (0) and exit (1) both results in execution of exit statement?
                
                        Syam said: 
                         
                        1 decade ago
                
                If I remove the main() in the program what happen?
Please explain?
                Please explain?
Post your comments here:
 
            
        Quick links
                            Quantitative Aptitude
                                    
                                    Verbal (English)
                                    
                                    Reasoning
                                    
                                Programming
                                    
                                    Interview
                                    
                                     Placement Papers