If Statement in Programming
20 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What will be printed if the user inputs var1 as 7 and var2 as 7 in the first code snippet?

  • var1 is greater than var2
  • var1 is not equal to var2
  • var1 is equal to var2 (correct)
  • var2 is greater than var1

In the second code snippet using the switch statement, what will be the output for marks input as 75?

  • first
  • third
  • second (correct)
  • fail

What does the ternary operator do in the third code snippet?

  • Checks if age is positive
  • Calculates the average of two ages
  • Determines if a person can vote based on age (correct)
  • Checks if age is a multiple of 18

In C programming, what is the primary purpose of a 'goto' statement?

<p>To escape from nested loops or go to error handling exits (B)</p> Signup and view all the answers

If num is input as 12 in the last code snippet, how many times will the printf statement inside 'table' be executed?

<p>11 times (C)</p> Signup and view all the answers

What is the output when age is entered as 20 in the third code snippet using ternary operator?

<p>You can vote (B)</p> Signup and view all the answers

What happens if there is a 'case 3' in the second code snippet's switch statement?

<p>'grade' gets assigned a value of 'third' (D)</p> Signup and view all the answers

What is the downside of using 'goto' statements too frequently in programming?

<p>Code readability decreases (A)</p> Signup and view all the answers

In the first code snippet, what will be printed if var1 is entered as 10 and var2 as 8?

<p>var1 is greater than var2 (A)</p> Signup and view all the answers

What will happen if no case matches the value of 'index' in the switch statement of the second code snippet?

<p>The default case 'fail' gets executed (A)</p> Signup and view all the answers

What is the purpose of the 'if' statement?

<p>To execute a block of code when a condition is true (C)</p> Signup and view all the answers

In the 'if-else' statement, what happens if the test expression is false?

<p>The 'else' block of code is executed (D)</p> Signup and view all the answers

What is the syntax of the 'if-else' statement?

<p>if (test expression) { statement block1; } else { statement block2; } (C)</p> Signup and view all the answers

What happens if more than one 'if-else' statement is nested?

<p>Only the innermost 'if-else' block is executed (A)</p> Signup and view all the answers

Which statement is printed in the output for the given code snippet? 12 10

<p><code>a is greater</code> (B)</p> Signup and view all the answers

What will be the output for this code snippet: 23 24?

<p><code>b is greater</code> (D)</p> Signup and view all the answers

'If-else' statements are primarily used for:

<p>Executing a block when a condition is true and another when it's false (B)</p> Signup and view all the answers

'If-else' statements can be nested to:

<p>Create complex decision-making structures with multiple conditions (A)</p> Signup and view all the answers

'If-else' statements are useful for handling situations where:

<p>'Else' conditions need to be independently validated after initial checks (A)</p> Signup and view all the answers

'If-else' statements provide a clear way of:

<p>'If-then' execution of code blocks based on conditions (B)</p> Signup and view all the answers

More Like This

Use Quizgecko on...
Browser
Browser