Decision Making using If Statement
17 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 is the purpose of the 'if' statement in decision making?

  • Always execute the statement block after 'if'
  • Repeat a group of statements
  • Execute a statement block when a test expression is true (correct)
  • Execute a statement block when a test expression is false
  • In decision making, what type of statement is the 'if-else' statement?

  • One-way decision statement
  • Two-way decision statement (correct)
  • Three-way decision statement
  • Unconditional statement
  • How does the 'if-else' statement differ from the 'if' statement in decision making?

  • If-else has more than two condition checks
  • 'If' statement is used for nested conditions
  • If-else has an 'else' block for false conditions (correct)
  • If-else always executes both blocks
  • What is necessary for an 'if-else' statement to execute the 'else' block?

    <p>'If' condition must be false</p> Signup and view all the answers

    What kind of decision-making scenario can be handled by nested if-else statements?

    <p>'if-else' with multiple conditions</p> Signup and view all the answers

    In nested if-else statements, what happens if the condition in 'if (test expression1)' is false?

    <p>'statement block2' is executed</p> Signup and view all the answers

    'If' statements are primarily used for:

    <p>'If a condition exists, then do this action'</p> Signup and view all the answers

    What will be the output of the first code snippet if the user inputs var1 as 10 and var2 as 10?

    <p>var1 is equal to var2</p> Signup and view all the answers

    In the second code snippet, what is the value of 'grade' if a user enters 45 for 'marks'?

    <p>third</p> Signup and view all the answers

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

    <p>Checks if age is greater than or equal to 18 and prints 'You can vote'</p> Signup and view all the answers

    In the fourth code snippet, what happens when the user enters a negative number for 'num'?

    <p>The program goes into an infinite loop</p> Signup and view all the answers

    How many operands does the ternary operator take?

    <p>3</p> Signup and view all the answers

    Which statement best describes the usage of a 'goto' statement in C programming?

    <p>'goto' should be avoided due to its complexity in code readability</p> Signup and view all the answers

    If a user enters 73 for 'marks' in the second code snippet, what will be the output for 'grade'?

    <p>'fail'</p> Signup and view all the answers

    What happens if a user doesn't input any value for 'marks' in the second code snippet?

    <p>'fail' is assigned to 'grade'</p> Signup and view all the answers

    What does the statement 'case 10: case 9: case 8: case 7: case 6: grade="first";' mean in the second code snippet?

    <p>'grade' will be assigned 'first' only if marks are between 6 and 10</p> Signup and view all the answers

    'case value-1 block-1 break;' represents which control structure in C programming?

    <p>'switch-case statement'</p> Signup and view all the answers

    More Like This

    Use Quizgecko on...
    Browser
    Browser