PIC QB
PIC QB
b) Definitions:
1) Assembler:
An assembler is a program that converts assembly language code into machine code (binary
instructions that a computer can understand).
Example: Assembly code (MOV A, B) is converted to binary (10110000).
2) Compiler:
A compiler translates the entire high-level language program (like C, C++) into machine code at
once before execution.
Example: gcc is a compiler for C language.
3) Interpreter:
A linker combines multiple object files into a single executable file by resolving function and
variable references.
Example: It links main.o and math.o to create a.out.
c) Else-if Ladder in C
The else-if ladder is used when multiple conditions need to be checked sequentially. If one
condition is true, the corresponding block executes, and the rest are skipped.
Syntax:
if (condition1) {
// Code block 1
}
else if (condition2) {
// Code block 2
}
else if (condition3) {
// Code block 3
}
else {
// Default block (if none of the above conditions are true)
}
Example:
#include <stdio.h>
int main() {
int marks;
printf("Enter your marks: ");
scanf("%d", &marks);
return 0;
}
An array is a collection of elements of the same data type stored in contiguous memory
locations. It allows multiple values to be stored under a single variable name and accessed using
an index.
Characteristics of an Array:
Example:
#include <stdio.h>
int main() {
int numbers[5] = {10, 20, 30, 40, 50}; // Declaring and initializing an
array
return 0;
}
e) Formatted Input and Output Statements in C
Formatted Input (scanf)
scanf is used to take input from the user with format specifiers to
specify the data type.
Format specifiers:
o %d for integers
o %f for floating-point numbers
o %c for characters
o %s for strings
Example:
#include <stdio.h>
int main() {
int age;
float salary;
char name[20];
// Formatted Input
printf("Enter your name: ");
scanf("%s", name);
// Formatted Output
printf("\nEmployee Details:\n");
printf("Name: %s\n", name);
printf("Age: %d years\n", age);
printf("Salary: %.2f INR\n", salary); // Displays salary with 2 decimal
places
return 0;
}
f) Declaration and Initialization of an Array in C
Declaration of an Array
data_type array_name[size];
Example:
1. At Declaration:
4. Using Loops:
#include <stdio.h>
int main() {
int numbers[5]; // Declare an array of size 5
return 0;
}
g) Program:
#include <stdio.h>
int main() {
int num1, num2, choice;
float result;
return 0;
}