Skip to content
Related Articles

Related Articles

Output of C programs | Set 65 (If-Else)

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Medium
  • Last Updated : 07 Sep, 2021

Prerequisite : Decision making in C
Question 1 
 

C




#include"stdio.h"
#include"stdlib.h"
void reverse(int i)
{
    if (i > 5)
         exit(0);
     printf("%d\n", i);
     return reverse(i++);
}
int main()
{
    reverse(1);
}

OPTIONS: 
a)Segmenation fault 
b)Compilation error 
c)Print 1 Infinite time 
d)Both a & c
 

OUTPUT:  (d)Both a & c

Explanation: 
We call the main method again and again by 1 because we use post-increment. At certain time stack frame will full means segmentation fault occurs.
Question 2 
 

C




#include"stdio.h"
int main()
{
    if(-1L>1UL)
        printf("paul is crazy");
    else
        printf("mannu is Crazy");
}

OPTIONS: 
a)mannu is Crazy 
b)paul is crazy 
 

OUTPUT:  (b)paul is crazy 

Explanation: 
Here ,comparison between long int and unsigned long int generally which is not possible. 
Now,long int is promoted to unsigned long int whose value will be 
(2^size_of_unsigned_long_int)-1.
Question 3 
 

C




#include"stdio.h"
int main()
{
    int i;
    if(i=0,2,3)
        printf("Geeksforgeeks ");
    else
        printf("Hello ");
    printf("%d\n",i);
}

OPTIONS: 
a)Hello 3 
b)Hello 0 
c)Geeksforgeeks 0 
d)Geeksforgeeks 3
 

OUTPUT:  (c) Geeksforgeeks 0

Explanation: At first zero will assign in ‘i’ then comma operator returns the last value which is 3 and condition becomes true.
Question 4 
 

CPP




#include"stdio.h"
int main()
{
    int i;
    if(i=(2,1,0))
        printf("Geeksforgeeks ");
    else
        printf("Hello ");
    printf("%d\n",i);
}

OPTIONS: 
a)Hello 3 
b)Geeksforgeeks 0 
c)Hello 0 
d)Geeksforgeeks 3
 

OUTPUT:  (c) Hello 0

Explanation: Priority of parenthesis bracket is greater than equal to(=) operator , So atfirst comma operator return the last value which is zero(0) and then equal to(=) operator assign 0 to ‘i’ and condition becomes false.
Question 5 
 

C




#include"stdio.h"
int main()
{
    float a=0.7d;
    if(a<0.7)
         printf("C");
        else
         printf("C++");
    return 0;
}

OPTIONS: 
a)Compilation error 
b)C++ 
c)C
 

OUTPUT:  (C)C 

Explanation: 
a = 0.7 is rounded to 0.699999988 
and the constant 0.7 is as 0.69999999999 
so a<0.7 is true so it print “c” 
but in case of 0.8 
a = 0.800000011 and 
constant 0.8 is 0.8000000000000000 
This article is contributed by Abhishek kurmi. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!