Open In App
Related Articles

Output of C programs | Set 47 (Decision and Control Statements)

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
Decision and Loops & Control Statements QUE.1 What is the output of this program ?
#include <stdio.h>
#include <stdio.h>
  
void main()
{
    while (printf("geeks")) {
    }
}

                    
OPTION a) geeks b) infinite time geeks c) Compile time error d) No Output
Answer: b
Explanation: printf returns the number of characters of “geeks”. It returns 5 and loop runs infinite times because 5>0 and it is neither increasing nor decreasing. So it will print “geeks” infinite times QUE.2 What is the output of this program?
#include <stdio.h>
  
int main()
{
    while (printf("geeks"))
        return 0;
}

                    
OPTION a) geeks b) infinite time geeks c) compile time error d) no output
Answer:  a
Explanation: printf returns the number of characters “geeks”. It will return 5 but when it enters int, the body of loop it will get “return 0” and terminates the program so it will print “geeks” only one time. QUE. 3 What is the output of this program ?
#include <stdio.h>
  
int main()
{
    if (printf("geeks"))
        switch (printf("for"))
            while (printf("geeks"))
                return 0;
}

                    
OPTION a) geeks b) for c) geeksfor d) geeksforgeeks
Answer: c
Explanation: if, switch and while are condition checkers in his () and print anything written in his (). In this program, first run if() and printf return “geeks” 5 and come to 2 switch. Now switch print “for” and printf return 3 and now switch find case 3 and case 3 is not in the program and it terminates the program and print only “geeksfor”. QUE.4 What is the output?
#include <stdio.h>
  
int main()
{
    if (printf("geeks") != 5) {
  
    } else
        printf("geeksforgeeks");
    return 0;
}

                    
OPTION a) geeks b) geeksforgeeks c) geeksgeeksforgeeks d) Compile Errors
Answer: c
Explanation: First time, the if block is checked after printing geeks. Then check condition if(printf(“geeks”)!=5). Here condition is false then go to else part and print “geeksforgeeks” also. Then, go to the else part and print then output is geeksgeeksforgeeks. QUE.5 What is output of this program?
#include <stdio.h>
#define int n = printf("geeks")
int main()
{
    int n = 10;
    printf("%d", n);
    return 0;
}

                    
OPTION a) geeks b) 10 c) geeks 10 d) Compile Errors
Answer: d
Explanation:Error: Invalid Initialization You cannot define a printf as a int n=printf(). The data definition has no type or storage class. Related Article : Quiz on Loop and Control structures

Last Updated : 18 Sep, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads