Knowee
Questions
Features
Study Tools

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

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the code will be "Good evening".

Here's the step by step explanation:

  1. The variable time is set to 20.
  2. The ternary operator ? : is used to check a condition - in this case, whether time is less than 18.
  3. If time is less than 18, the code after the ? would run, which is printf("Good day").
  4. If time is not less than 18, the code after the : would run, which is printf("Good evening").
  5. Since time is 20 and 20 is not less than 18, the code printf("Good evening") runs.
  6. Therefore, "Good evening" is printed to the console.

This problem has been solved

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

1/3

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.