Mid bank -1-small question answers
Mid bank -1-small question answers
- putchar(char); – This function writes a single character to the standard output (usually
console).
Example:
putchar('A');
6. **Write the basic input and output functions used in C with syntax? (K1)**
- **Input Function (scanf())**: Used to take input from the user.
Syntax:
- **Logical Operators**: Used in conditional expressions that return either `true` or `false`.
Examples include `&&` (logical AND), `||` (logical OR), and `!` (logical NOT). They work on
boolean expressions.
Examples include `&` (bitwise AND), `|` (bitwise OR), `^` (bitwise XOR), and `~` (bitwise
NOT). These operate directly on the binary representations of integers.
11. **What is the difference between type conversion and type casting? (K2)**
- **Type Conversion**: This is an automatic process done by the compiler, where data
types are implicitly converted to a larger or compatible data type (e.g., converting an `int` to
`float`).
- **Type Casting**: This is an explicit conversion done by the programmer to change one
data type to another (e.g., casting a `float` to `int` using `(int)`).
---
Unit 2
if (condition) {
// statements
} else {
// statements
}
- **Flowchart**:
-refer class notes
if (condition1) {
// statements
} else if (condition2) {
// statements
} else {
// statements
}
- **Flowchart**:
- refer class notes
do {
// statements
} while (condition);
- **Flowchart**:
- refer class notes
- **Flowchart**:
-refer class notes
switch (expression) {
case constant1:
// statements
break;
case constant2:
// statements
break;
default:
// statements
}
- **Flowchart**:
- refer class notes
while (condition) {
// statements
}
- **Flowchart**:
- refer class notes
11. **Write a C program to swap two numbers using a third variable. (K3)**
#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
temp = a;
a = b;
b = temp;
printf("After swapping: a = %d, b = %d", a, b);
return 0;
}