PPS Assignment-2 Solutions
[A] Short Answer Type Questions
1. Differentiate between operator and operands.
- Operator: A symbol that performs operations on variables and values.
Example: +, -, *, /
- Operand: The values on which operators perform operations.
Example: In 'a + b', 'a' and 'b' are operands, '+' is an operator.
2. Define Explicit type conversion with suitable example.
- Explicit type conversion is when a programmer manually converts one data type into another.
Example: (float)10 / 3 results in 3.333 instead of integer division.
3. Define Conditional operator with an example.
- Conditional operator (ternary operator) is used for decision making.
Syntax: condition ? expression1 : expression2
Example: int min = (a < b) ? a : b;
4. Write limitation of Switch case.
- Switch case cannot handle non-integer values such as floating points or strings.
- It does not support range-based conditions.
5. Explain Break and Continue statements with an example.
- Break: Exits the loop or switch statement immediately.
Example:
for(int i = 0; i < 5; i++) {
if (i == 3) break;
printf('%d', i);
}
- Continue: Skips the current iteration and moves to the next.
Example:
for(int i = 0; i < 5; i++) {
if (i == 3) continue;
printf('%d', i);
}
[B] Long Answer Type Questions
1. What is the importance of Precedence order and Associativity? Explain Bitwise and Ternary
Operator.
- Precedence determines the order of execution in an expression.
- Associativity decides how operators with the same precedence are evaluated.
Example: Multiplication (*) has higher precedence than addition (+).
- Bitwise Operators: &, |, ^ (operate on bits of integers).
- Ternary Operator: condition ? true_value : false_value.
2. Discuss the concept of type casting and type conversion with a program.
- Type Casting: Explicit conversion using (data_type).
- Type Conversion: Automatic conversion by compiler.
Example:
float result = (float)10 / 3;
3. Write a program to discuss the use of break in switch statement.
Example:
switch(choice) {
case 1: printf('One'); break;
case 2: printf('Two'); break;
default: printf('Invalid');
}
4. Compare if..else..if ladder and switch case. Write a menu-driven program for a calculator.
- if..else..if allows range-based conditions; switch is limited to discrete values.
Example Calculator:
switch(op) {
case '+': result = a + b; break;
case '-': result = a - b; break;
}
5. Explain different types of operators in C. What differentiates operators with the same
precedence?
- Arithmetic, Relational, Logical, Bitwise, Assignment, and Ternary operators.
- Associativity determines execution order when precedence is the same.