What is the output of this code?int time = 20;(time < 18) ? printf("Good day") ; printf("Good evening");Group of answer choicesGood dayGood eveningNone of the above
Question
What is the output of this code?int time = 20;(time < 18) ? printf("Good day") ; printf("Good evening");Group of answer choicesGood dayGood eveningNone of the above
Solution
The output of the code will be "Good evening".
Here's the step by step explanation:
- The variable
timeis set to 20. - The ternary operator
? :is used to check a condition - in this case, whethertimeis less than 18. - If
timeis less than 18, the code after the?would run, which isprintf("Good day"). - If
timeis not less than 18, the code after the:would run, which isprintf("Good evening"). - Since
timeis 20 and 20 is not less than 18, the codeprintf("Good evening")runs. - Therefore, "Good evening" is printed to the console.
Similar Questions
CWhat is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}
What is the output of the code given below?#include <stdio.h> void main() { int i; for (i = 5; i < 10; i++); printf("%d ", i);}Options5105 6 7 8 99
What is the output of the programme below?public static void main(String[] args) { int x = 0; while (x < 10) { if (x & 2 == 0) { System.out.print(x + “ “); } x++; }}Group of answer choices1 3 5 7 92 4 6 8 100 2 4 6 80 1 2 3 4
What is the output of the following code snippet?#include <stdio.h>int main() { int x = 5; if (x > 2) { printf("A"); if (x < 5) { printf("B"); } } else { printf("C"); } return 0;}
What will be the output of the following program?#include<stdio.h>int main() { int fun(int); int i = fun(10); printf("%d\n", --i); return 0; } int fun(int i) { return (i++);}Select one:810119
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.