0
0
Cprogramming~5 mins

If statement in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of an if statement in C?
An if statement lets the program decide to run some code only if a condition is true. It helps the program make choices.
Click to reveal answer
beginner
Write the basic syntax of an if statement in C.
The basic syntax is:<br>
if (condition) {
    // code to run if condition is true
}
Click to reveal answer
beginner
What happens if the condition in an if statement is false?
If the condition is false, the code inside the if block is skipped and the program continues after the block.
Click to reveal answer
beginner
How do you add an alternative action if the if condition is false?
You use an else block after the if block:<br>
if (condition) {
    // code if true
} else {
    // code if false
}
Click to reveal answer
intermediate
Can you have multiple conditions checked in sequence? How?
Yes, by using else if blocks between if and else to check more conditions one after another.
Click to reveal answer
What does the if statement do in C?
ARepeats code multiple times
BEnds the program
CDefines a new variable
DRuns code only if a condition is true
Which symbol is used to compare equality in an if condition?
A==
B=
C!=
D&&
What happens if the if condition is false and there is no else?
AThe program crashes
BThe code inside <code>if</code> runs anyway
CThe code inside <code>if</code> is skipped
DThe program asks for input
How do you check multiple conditions in order?
AUsing multiple <code>if</code> statements without <code>else</code>
BUsing <code>else if</code> blocks
CUsing a <code>switch</code> statement only
DUsing a loop
Which of these is a correct if statement in C?
Aif (x == 5) { }
Bif (x = 5) { }
Cif x = 5 { }
Dif x == 5 then { }
Explain how an if statement works in C and write a simple example.
Think about how you decide to do something only if a condition is met.
You got /4 concepts.
    Describe how to handle two different actions based on a condition using if and else.
    Imagine choosing between two paths depending on a yes/no question.
    You got /4 concepts.