Knowee
Questions
Features
Study Tools

What will be the output of following program?main( ){int k, num = 30 ;k = ( num > 5 ? ( num <= 10 ? 100 : 200 ) : 500 ) ;printf ( "\n%d", num ) ;}

Question

What will be the output of following program?main( ){int k, num = 30 ;k = ( num > 5 ? ( num <= 10 ? 100 : 200 ) : 500 ) ;printf ( "\n%d", num ) ;}

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

Solution

The output of the program will be 30.

Here's the step by step explanation:

  1. The program starts with the main function.
  2. Inside the main function, two integer variables 'k' and 'num' are declared. 'num' is initialized with the value 30.
  3. The next line is a ternary operator which is a shorthand for an if-else statement. It checks if 'num' is greater than 5. If it is, it checks if 'num' is less than or equal to 10. If 'num' is less than or equal to 10, 'k' is assigned the value 100. If 'num' is greater than 10, 'k' is assigned the value 200. If 'num' is not greater than 5, 'k' is assigned the value 500. In this case, since 'num' is 30, 'k' is assigned the value 200.
  4. The printf statement prints the value of 'num', which is 30.
  5. The program ends.

This problem has been solved

Similar Questions

What will be the output of the following C code   #include <stdio.h> int main() { int x = 20;  x %= 3;  printf("%d",x); return 0; }

What will be the output of the following program?#include<stdio.h> int X=40; int main() {     int X=20;     printf("%d", X);     return 0; }Select one:400Error20

hat will be the output of the following code snippet?123456#include <stdio.h>int main() { int num = 20; printf("%d", num >= 20 && num <= 30); return 0;}

What is The Output of the following program? #include<stdio.h> void main() { int i = printf("00"); int i =printf("00"); printf("%d",i); } 0 00 002

What will be the output of the C program?#include<stdio.h>int main(){ char num = '\010'; printf("%d", num); return 0;}a.10b.8c.10d.8

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.