IMPORTANT PRACTICE QUESTIONS (FOR,WHILE ,DO WHILE LOOP,IF ,IF ELSE,
CONDITIONAL BRANCHING PROGRAMS )
1. What is operator precedence in C?
Operator precedence in C dictates the order in which the operators will be evaluated in an
expression. Associativity, on the other hand, defines the order in which the operators of the
same precedence will be evaluated. Associativity can occur from either left to right or right to
left.
Example:
1. x = + 20
1 + 20 = 21
2. 10 / (10 + 20)
= 0.3
Without rules, different solutions are obtained. Therefore, precedence is defined; division has
precedence over addition, so case 1 is correct.
Operator Precedence and Associativity Table
NAME ASSOCIATIVITY PRECEDENCE
() function call, [] Array Left to Right 14
Subscript, . Dot, -> Arrow
, ++ Increment, -- Right to Left 13
Decrement
~ one's compliment, &
address operator
* Multiplication, % Modulus, Left to Right 12
/ Division
+ Addition, - Subtraction Right to Left
2. Name three conditional branching statements along with their
syntax.
The conditional branching statements help to jump from one part of the program to another
depending on whether the condition is satisfied or not.
(i) if statement
The if statement is the most simple decision-making statement. It is used to decide if a certain
condition is true, then a block of code or statement is executed; otherwise not.
Syntax:
if (condition)
{
statement 1;
// ...
statement x;
}
,Example:
#include <stdio.h>
int main()
{
int i = 10;
if (i < 15)
{
printf("value is greater than 15");
}
}
(ii) Nested if Statement
A nested if statement means an if statement inside another if statement.
Syntax:
if (condition 1)
{
if (condition 2)
{
statement 1;
}
}
Example:
, #include <stdio.h>
int main()
{
int x = 65, y = 35, z = 2;
if (x > y)
{
if (x > z)
{
printf("x is greater than y and z");
}
}
printf("End of program");
}
(iii) if-else Statement
The if statement executes if a specified condition is true. If the condition is false, the else
statement can be executed.
Syntax:
if (condition)
{
Statement 1;
}
else
{
Statement 2;
}
Example: