0% found this document useful (0 votes)
9 views8 pages

Unit Ii

Uploaded by

Kore Ramesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

Unit Ii

Uploaded by

Kore Ramesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIT II

1. What is an operator and list operators.


An operator is a symbol. perform operations like arithmetic or logical manipulations.
Ex:
+, -, *, /, %, &&, ||

2. Explain about Ternary Operator in C.


The ternary operator (? .) is a shorthand for an if-else statement, taking three operands.

3. Define expression.
An expression is a combination of variables, constants, and operators that yields a value.

4. What is precedence and associativity rule.


Precedence defines operator evaluation order; associativity defines evaluation order for
operators of the same precedence.

5. What is Typecasting in C.
Typecasting is converting one data type to another.

6. Write about ‘continue’ statement in C.


The continue statement skips the current loop iteration and proceeds to the next.

7. Write about ‘break’ statement in C.


The break statement exits a loop or switch statement.

8. Define nested loop.


A nested loop is a loop within another loop.

1|Page
UNIT II

9. Write about nested if else statement.


A nested if-else has an if-else inside another if-else.

10. What is a null statement.


A null statement does nothing, represented by ; .

11. What is dangling else problem.


The dangling else problem occurs when an else is ambiguously associated with an if.

12. Write about explicit type conversion.


Explicit type conversion (casting) manually changes a variable's type.

13. Write about nested if else statement.


A nested if-else has an if-else inside another if-else.

14. Define operator and explain various operators in C.

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:

1. Arithmetic Operators: Perform mathematical operations.


Ex: +, -, *, /, %

int sum = a + b;

2. Relational Operators: Compare two values.


Ex: ==, !=, >, <, >=, <=

if (a > b) {

...

2|Page
UNIT II
3. Logical Operators: Perform logical operations.
Ex:

&&, ||, !
if (a > 0 && b > 0)

...

4. Bitwise Operators: Perform operations at the bit level.


Ex:

&, |, ^, ~, <<, >>

int result = a & b;

5. Assignment Operators: Assign values to variables.


Ex:

=, +=, -=, *=, /=

a += 10; // Equivalent to a = a + 10
6. Unary Operators: Operate on a single operand.
Ex:
++, --, -, +

a++;

7. Conditional (Ternary) Operator: Returns a value based on a condition.


Ex:

?:

int max = (a > b) ? a : b;

15. What is an expression? Explain various types of expressions in C with


examples.

Definition:
An expression is a combination of variables, constants, and operators that evaluates to a
single value.

3|Page
UNIT II
Types of Expressions:

1. Arithmetic Expressions: Perform mathematical calculations.

int sum = a + b * c;

2. Relational Expressions: Compare two values and return a boolean result.

if (a > b) {

...

}
3. Logical Expressions: Combine two or more conditions.

if (a > 0 && b > 0) {

...

4. Bitwise Expressions: Operate at the bit level.

int result = a & b;

5. Conditional Expressions: Use the ternary operator for decision-making.

int max = (a > b) ? a : b;

16. Discuss in brief about:

a. Implicit Type Conversion:

 Automatic conversion of a smaller data type to a larger one by the compiler.

 Example: Converting int to float.

int a = 10;

float b = a; // Implicit conversion


b. Explicit Type Conversion:

 Manually converting a data type using typecasting.

 Example: Converting float to int.

float a = 10.5;

int b = (int)a; // Explicit conversion

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:

1. Expression Statements: Perform operations.

a = b + c;

2. Compound Statements: Group multiple statements.

int a = 10;

printf("%d", a);
}

3. Control Statements: Control the flow of execution.


Ex:

if, switch, for, while.

4. Jump Statements: Transfer control.


Ex:

break, continue, goto.

18. What is a conditional statement? Explain various types of conditional


statements.

Definition:
A conditional statement allows decision-making by executing code blocks based on
conditions.

Types of Conditional Statements:

1. if Statement: Executes a block if the condition is true.

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) {

printf("Both are positive");

4. else if Ladder: Multiple conditions.

if (a > b) {
...

else if (a < b) {

...

else {

...
}

5. switch Statement: Multi-way decision-making.

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.

Use of break and default:

1. break:

o Terminates the execution of a case and exits the switch block.

o Prevents fall-through to the next case.

switch (choice) {

case 1: printf("One");
break;

case 2: printf("Two");

break;

2. default:

o Executes when no other case matches.

o Optional but recommended.


switch (choice) {

case 1: printf("One");

break;

case 2: printf("Two");

break;

default: printf("Invalid");

}
7|Page
UNIT II

20. Define iteration/looping statement. Explain different looping statements in C.

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:

o Used when the number of iterations is known.

for (int i = 0; i < 5; i++)

printf("%d ", i);

}
2. while Loop:

o Executes while a condition is true.

int i = 0;

while (i < 5) {

printf("%d ", i);

i++;

3. do-while Loop:
o Executes at least once, even if the condition is false.

int i = 0;

do {

printf("%d ", i);

i++;

} while (i < 5);

8|Page

You might also like