Unit Ii
Unit Ii
3. Define expression.
An expression is a combination of variables, constants, and operators that yields a value.
5. What is Typecasting in C.
Typecasting is converting one data type to another.
1|Page
UNIT II
Definition:
An operator in C is a symbol that performs an operation on one or more operands to
produce a result.
Types of Operators in C:
int sum = a + b;
if (a > b) {
...
2|Page
UNIT II
3. Logical Operators: Perform logical operations.
Ex:
&&, ||, !
if (a > 0 && b > 0)
...
a += 10; // Equivalent to a = a + 10
6. Unary Operators: Operate on a single operand.
Ex:
++, --, -, +
a++;
?:
Definition:
An expression is a combination of variables, constants, and operators that evaluates to a
single value.
3|Page
UNIT II
Types of Expressions:
int sum = a + b * c;
if (a > b) {
...
}
3. Logical Expressions: Combine two or more conditions.
...
int a = 10;
float a = 10.5;
4|Page
UNIT II
17. Define statement. Explain in brief about types of statements.
Definition:
A statement in C is a single instruction that performs an action.
Types of Statements:
a = b + c;
int a = 10;
printf("%d", a);
}
Definition:
A conditional statement allows decision-making by executing code blocks based on
conditions.
if (a > b) {
printf("A is greater");
5|Page
UNIT II
2. if-else Statement: Executes one block if true, another if false.
if (a > b) {
printf("A is greater");
else {
printf("B is greater");
}
3. Nested if Statement: if within another if.
if (a > 0) {
if (b > 0) {
if (a > b) {
...
else if (a < b) {
...
else {
...
}
switch (choice) {
case 1: printf("One");
break;
case 2: printf("Two");
6|Page
UNIT II
break;
default: printf("Other");
19. Define switch statement. Explain in brief about the use of break and default
with switch statement.
Definition:
A switch statement is a multi-way decision-making control structure that tests the value
of an expression and executes the corresponding case.
1. break:
switch (choice) {
case 1: printf("One");
break;
case 2: printf("Two");
break;
2. default:
case 1: printf("One");
break;
case 2: printf("Two");
break;
default: printf("Invalid");
}
7|Page
UNIT II
Definition:
An iteration or looping statement repeatedly executes a block of code if a condition is
true.
Types of Looping Statements in C:
1. for Loop:
}
2. while Loop:
int i = 0;
while (i < 5) {
i++;
3. do-while Loop:
o Executes at least once, even if the condition is false.
int i = 0;
do {
i++;
8|Page