quiz image

Decision Making using If Statements

SprightlyVision avatar
SprightlyVision
·
·
Download

Start Quiz

Study Flashcards

16 Questions

What is the purpose of using the if-else statement in decision making?

To execute a specific block of statements if the test expression is false

In the given code snippet, what will be the output when the user enters the numbers 12 and 10?

a is greater

Which statement type allows for nested conditions in decision making?

Nested if-else statement

What happens if a test expression in an if-else statement evaluates to true?

The if block is skipped

What is the purpose of an if-else ladder statement?

To provide multiple conditions to choose from

How does a nested if-else statement differ from a regular if-else statement?

A nested if-else can have multiple levels of conditions

What will be the output when the value of var1 is 21 and the value of var2 is 12 in the given code?

var2 is greater than var1

In the switch statement example provided, what grade will be printed if a user enters marks as 74?

first

For a person aged 22, what will be the output of the ternary operator in the given ternary operator code snippet?

You can vote

When using the goto statement in C, in what situations would you typically use a label?

To handle error conditions within nested loops

What will be the output of the table printing code if the user enters the number 5?

5 x 1 = 5

In C programming, what happens if there are no 'break' statements in a switch case block?

The next case block will execute as well

Which operator cannot be replaced by a ternary operator in C programming?

'switch' statement

'Labels' used with 'goto' statements in C programming have a specific naming requirement. What is it?

'labelname:'

'Goto' statements in C programming can be used for which of the following purposes?

Looping within functions

'Ternary' operators in C are best suited for which type of operations?

Complex logical conditions

Study Notes

Decision Making using If

  • If statement is a two-way decision statement used in conjunction with an expression.
  • Syntax: if (test expression) { statement block; } statement-x;
  • If the test expression is true, the statement block after if is executed, otherwise it is not executed.

If-Else Statement

  • Used when there is another set of statements to be executed if the condition is false.
  • Syntax: if (test expression) { statement block1; } else { statement block2; } statement-x;

Nested If-Else Statement

  • Used when more than one if-else statement is needed.
  • Syntax: if (test cond1) { if (test expression2) { statement block1; } else { statement block2; } } else { statement block2; } statement-x;

Switch Case Statement

  • Used when there are more than one valid choices to choose from.
  • Syntax: switch(expression) { case value-1: block-1; break; case value-2: block-2; break; ... default: default block; break; } statement-x;

Ternary Operator

  • Syntax: Test condition ? expression1 : expression2;
  • If the test condition is true, expression1 is executed, otherwise expression2 is executed.
  • Takes 3 operands: condition, expression1, and expression2.

GoTo Statement

  • Used to escape from multiple nested loops or to go to an error handling exit at the end of a function.
  • A label is required when using a goto statement.
  • Labels have their own namespace and can't clash with variable or function names.

This quiz covers the basics of decision making in programming using if statements. Learn how to execute specific statements based on conditions and loop through statements until certain conditions are met. Explore the syntax and usage of if statements in programming.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Control Statements in Programming
10 questions

Control Statements in Programming

SubstantiveArcticTundra avatar
SubstantiveArcticTundra
Decision Making using If Statements
20 questions
If Statements in Programming
18 questions
Use Quizgecko on...
Browser
Browser