UNIT-1
1. What is the history of computers?
History of computers: Evolution of computing devices from early mechanical calculators to
modern electronic computers, including generations of computers (vacuum tubes, transistors,
integrated circuits, microprocessors).
2. What are the basic components of a computer organization?
Basic components of a computer: CPU (ALU + control unit), input units, output units, memory, and
storage.
3. What does ALU stand for, and what is its function?
ALU: Arithmetic Logic Unit – performs arithmetic (add, subtract) and logical (AND, OR, NOT)
operations.
4. What are input-output units in a computer?
Input-output units: Devices for entering data (keyboard, mouse) and displaying results (monitor,
printer).
5. What is the role of memory in a computer?
Role of memory: Stores data and instructions temporarily (RAM) or permanently (ROM, storage)
for processing.
6. What is a program counter?
Program counter: A CPU register that holds the address of the next instruction to be executed.
7. What are programming languages? Give examples.
Programming languages: Languages used to write programs (e.g., C, Java, Python). They are
classified into low-level (machine/assembly) and high-level languages.
8. What is an algorithm?
Algorithm: A step-by-step procedure or set of rules to solve a problem or perform a task.
9. What is a flowchart? Which tool can be used to create flowcharts?
Flowchart: A diagrammatic representation of an algorithm using symbols (Dia is a tool for
drawing flowcharts).
10. What is pseudo code?
Pseudo code: A textual, informal description of an algorithm using simple English-like statements.
11. What is the difference between compilation and execution?
Compilation vs Execution: Compilation translates source code into machine code (object code).
Execution runs the machine code to perform the program’s tasks.
12. What are primitive data types in programming?
Primitive data types: Basic data types like int, float, char, double, etc., that represent single values.
13. What are variables in programming?
Variables: Named storage locations that hold data which can change during program execution.
14. What are constants in programming?
Constants: Fixed values that do not change during program execution.
Example: const int MAX = 10;
15. How are basic input and output operations performed in a program?
Input/output operations: Using functions like scanf() or cin for input and printf() or cout for
output.
16. What is type conversion?
Type conversion: Automatic (implicit) conversion of one data type to another by the compiler.
Example: int to float.
17. What is type casting?
Type casting: Explicit conversion of a variable from one type to another using casting operators.
Example: (int)x. //convert float variable x into int type.
18. What is the difference between type conversion and type casting?
Type conversion vs casting: Type conversion is automatic and implicit, while casting is explicit
and user-defined.
19. Why are algorithms important in problem-solving?
Importance of algorithms: Algorithms provide a systematic approach to solving problems
efficiently and are the foundation of programming.
20. How do you represent an algorithm using a flowchart and pseudo code?
Representing algorithms: Flowcharts use graphical symbols to depict steps, while pseudo code
uses textual statements to describe the logic.
21)What is time complexity in algorithms?
Time complexity refers to the amount of time an algorithm takes to complete, usually measured in
terms of the input size (n).
Common Time Complexities:
O(1) - Constant Time
O(log n) - Logarithmic Time
O(n) - Linear Time
22)What is space complexity in algorithms?
Space complexity refers to the amount of memory an algorithm uses, usually measured in terms of
the input size (n). Common space complexities include:
O(1) - Constant Space
O(log n) - Logarithmic Space
O(n) - Linear Space
23)What are ternary operators? Give an example.
The conditional operator is also called as ternary operator because it requires three operands. This
operator is used for decision making.
Syntax: Condition ? TRUE Part : FALSE Part ;
24)What is the difference between ++i and i++?
++i (Prefix Increment): The ++i operator increments the value of i before the value is used in the rest of
the expression.
i++ (Postfix Increment): The i++ operator increments the value of i after the original value has been used
in the rest of the expression.
UNIT-2
[Link] are simple sequential programs?
Simple sequential programs: Programs that execute statements one after another in a straight-line
sequence without any branching or looping.
2. What is the purpose of conditional statements in programming?
Purpose of conditional statements: To make decisions in a program and execute different blocks
of code based on whether a condition is true or false.
3. What is an if statement?
if statement: Executes a block of code only if a specified condition is true.
Syntax: if(condition)
{
----True statements----
}
4. How does an if-else statement work?
if-else statement: Executes one block if the condition is true and another block if it is false.
Syntax: if(condition)
{
----True statements----
}
else
{
----False statements----
}
5. What is a switch statement used for?
switch statement: Selects one of many code blocks to execute based on the value of an expression.
Syntax: switch(Expression)
{
Case 1: ----True statements----; break;
Case 2: ----True statements----; break;
--------------
--------------
default: ----False statements----;
}
6. What are loops in programming?
Loops: Control structures that repeat a block of code multiple times until a condition is met.
Example: while, do..while, for
7. How does a for loop operate?
for loop: A loop with initialization, condition, and increment/decrement in a single line.
8. What is the syntax of a while loop?
while loop: Checks the condition before executing the loop body.
Syntax: while(condition)
{
----statements-----
Increment/decrement statement
}
9. How does a do-while loop differ from a while loop?
do-while vs while: do-while executes the body first and then checks the condition (guarantees at
least one execution).
10. When should you use a break statement?
break statement: Terminates the nearest enclosing loop or switch, transferring control to the
next statement after the loop.
11. What does the continue statement do?
continue statement: Skips the remaining code in the current iteration and jumps to the next
iteration of the loop.
12. What is the difference between break and continue?
break vs continue: break exits the loop entirely; continue skips only the current iteration.
13. Can you nest conditional statements? Give an example scenario.
Nesting conditionals: Placing an if or switch inside another if or loop to handle complex decision-
making.
14. How do you choose between if-else and switch?
if-else vs switch: Use if-else for complex or range-based conditions; use switch for multiple
discrete value checks.
15. What is an entry-controlled loop?
Entry-controlled loop: Condition is checked before entering the loop (for, while).
16. What is an exit-controlled loop?
Exit-controlled loop: Condition is checked after executing the loop body (do-while).
17. How do you prevent infinite loops?
Preventing infinite loops: Ensure the loop condition eventually becomes false or use break
appropriately.
18. What are the common uses of loops in programming?
Uses of loops: Iterating over arrays, repetitive tasks, processing data collections, implementing
algorithms.
UNIT-3
1)What is an array?
A collection of elements of the same data type stored in contiguous memory locations.
2. How are array elements accessed?
Using an index (subscript) like arr[i].
3. What is array indexing?
The position of an element in an array, usually starting from 0.
4. Explain the memory representation of a 1‑D array.
Elements are stored sequentially in memory; the array name points to the first element (base
address).
5. Write the syntax to declare an integer array of size 10.
int a[10];
6. How do you initialize an array in C?
7. What is the base address of an array?
The memory address of the first element (&arr[0]).
8. How are array elements stored in memory?
In contiguous locations, each occupying sizeof(type) bytes.
9. What is a two‑dimensional array?
An array of arrays; a matrix with rows and columns.
10. Write the declaration of a 2‑D array with 3 rows & 4 columns.
int a[3][4];
11. How is a 2‑D array stored in memory? (row‑major vs column‑major)
C uses row‑major order: all elements of a row are stored consecutively.
12. How do you access an element in a 2‑D array?
matrix[row][col].
13. What is the difference between a 1‑D and 2‑D array?
1‑D is a linear list; 2‑D is a table with rows & columns (nested arrays).
14. Write a program snippet to sum all elements of an integer array.
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int n = sizeof(arr) / sizeof(arr[0]);
int sum = 0;
for (int i = 0; i < n; i++) {
sum += arr[i]; // Add the current element to the sum
}
printf("The sum of all elements is: %d\n", sum);
return 0;}
15. How do you find the length of an array in C?
sizeof(arr) / sizeof(arr[0]) (works for static arrays).
16. What is a string in C?
A character array terminated by a null character \0.
17. How is a string represented in memory?
Contiguous chars + a \0 at the end marking its end.
18. What is the role of the null character (\0) in a string?
It signifies the end of the string for functions like printf().
19. Write the declaration and initialization of a string.
char str[25]="MADHU";
(or)
char str[10]={ 'M','a','d','h','u','\0'};
20. Name three standard string functions in C.
strlen(), strcpy(), strcmp().
21. What does strlen() do?
Returns the length of a string (excluding \0).
22. How does strcpy() work?
Copies source string to destination string including \0.
23. What is the difference between strcmp() and strncmp()?
strcmp() compares full strings; strncmp() compares up to n characters.
24. How do you concatenate two strings in C?
Using strcat(dest, src).
25. How do you pass an array to a function in C?
Pass the array name (base address); use void func(int arr[], int size)
26. What are the limitations of arrays in C?
Fixed size (static), no bounds checking, homogeneous elements.
27. Explain array out‑of‑bounds access.
Accessing an index ≥ size leads to undefined behavior (memory corruption).
28. How can you prevent array overflow errors?
Check indices against array size; use loops with bounds or dynamic containers.
UNIT-4
[Link] is a pointer?
A variable that stores the memory address of another variable.
Example: int *p;
2. What does the address operator & do?
Returns the memory address of a variable
3. *What does the dereference operator * do?*
Accesses the value stored at the address pointed to by a pointer.
4. How do you declare a pointer to an integer?
Example: int a=10;
int *p=&a;
5. What is pointer initialization?
Assigning a valid address to a pointer, e.g., int *p = &x;.
6. Explain pointer arithmetic.
Operations like +, - move the pointer by multiples of the data type size.
7. *How does ptr + 1 behave for an int* pointer?*
It points to the next integer location (address + sizeof(int)).
8. What is the difference between ptr++ and *ptr++?
ptr++ increments the pointer; *ptr++ dereferences the current value then increments the pointer.
9. How can you access an array element using pointers?
arr[i] is equivalent to *(arr + i).
10. Write a snippet to traverse an array using pointer notation.
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int size = sizeof(arr) / sizeof(arr[0]);
int *ptr = arr;
printf("Traversing array using pointer notation:\n");
for (int i = 0; i < size; i++) {
printf("Element %d: %d\n", i + 1, *ptr);
ptr++;
}
return 0;
}
11. What is dynamic memory allocation?
Allocating memory at runtime using library functions (heap memory).
12. Name the dynamic memory allocation functions in C.
malloc(), calloc(), realloc(), free()
13. What does malloc() do?
Allocates a block of uninitialized memory and returns its address.
14. How do you allocate memory for an integer using malloc()?
#include <stdio.h>
#include <stdlib.h>
int main() {
int *ptr; // Declare a pointer to an integer
ptr = (int*) malloc(sizeof(int));
if (ptr == NULL) {
printf("Memory allocation failed!\n");
return 1; // Exit the program if allocation fails
}
*ptr = 100;
printf("Value stored in allocated memory: %d\n", *ptr);
free(ptr);
return 0;
}
15. What is the purpose of calloc()?
Allocates memory for an array, initializes it to zero.
16. How does realloc() work?
Resizes a previously allocated memory block, copying existing data.
17. Why is free() used?
Releases dynamically allocated memory to prevent leaks.
18. What happens if you forget to free() allocated memory?
Memory leak – unused memory remains occupied.
19. What is a user‑defined data type?
A custom type created by the programmer (struct, union, enum).
20. What is a structure in C?
A collection of heterogeneous data items grouped under one name.
21. Write the syntax to declare a structure named Student.
struct Student
{
int sno;
char name[10];
float height;
}
22. How do you access a structure member using the dot (.) operator?
[Link] or [Link]
23. How do you access structure members via a pointer? (arrow -> operator)
ptr->roll is equivalent to (*ptr).roll.
24. What is a union in C?
A data type that shares the same memory for all its members (only one active).
25. How does memory allocation differ between structure and union?
struct allocates sum of member sizes; union allocates size of the largest member.
26. Can you nest a structure inside another structure?
Yes. Example: struct A { struct B b; };.
27. What is the typedef keyword used for?
Creates an alias for an existing data type.
28. Write a typedef for a structure Point.
typedef struct
{
int x;
int y;
} Point;
29. How do you dynamically allocate memory for a structure?
struct course {
int marks;
char subject[30];
};
struct course *ptr;
ptr = (struct course *)malloc(noOfRecords * sizeof(struct course));
30. What are the advantages of using pointers with structures?
Enables dynamic allocation, efficient passing to functions, and linked data structures.
UNIT-5
[Link] is a function in C?
A self‑contained block of code that performs a specific task and can be called by name.
2. What is the difference between function declaration and definition?
Declaration provides the function’s signature (prototype); definition includes the actual code
body.
3. Write the syntax for a function declaration.
return_type function_name(parameter_list);
4. What is a function prototype?
A declaration that specifies the function’s name, return type, and parameters (used for forward
reference).
5. How do you call a function in C?
By using its name with actual arguments: function_name(arg1, arg2);
6. What are the different types of function return values?
Any valid data type (int, float, void, pointers, structs, etc.) or void (no return).
7. Can a function return multiple values? If not, how can you achieve it?
No. Use pointers or a struct to return multiple values indirectly.
8. What are function arguments?
Variables passed to a function to supply input data.
9. Explain pass‑by‑value in functions.
A copy of the argument is passed; changes inside the function don’t affect the original variable.
10. Explain pass‑by‑reference (using pointers) in functions.
The address of the variable is passed; the function can modify the original variable via
dereferencing.
11. How do you pass an array to a function?
Pass the array name (base address); the function receives a pointer to the first element.
12. What happens to an array when passed to a function?
It decays to a pointer to its first element; size information is lost.
13. What is a recursive function? Give an example.
A function that calls itself. Example: factorial int fact(int n) { return n <= 1 ? 1 : n * fact(n-1); }.
14. What is the base condition in recursion?
The terminating condition that stops further recursive calls (prevents infinite recursion).
15. What is a file in C programming?
A stream of bytes stored on a storage device, accessed via file‑handling functions.
16. Name the file handling functions in C.
fopen(), fclose(), fread(), fwrite(), fscanf(), fprintf(), fgetc(), fputc(), etc.
17. What does fopen() do?
Opens a file and returns a FILE * pointer for subsequent operations.
18. What are the modes used in fopen()?
"r" (read), "w" (write), "a" (append), "r+" (read/write), "w+" (read/write, truncate), etc.
19. What is the purpose of fclose()?
Closes an open file, flushing buffers and releasing the FILE pointer.
20. Explain fscanf() and fprintf() for formatted file I/O.
fscanf() reads formatted data from a file; fprintf() writes formatted data to a file.
21. How do you check for end‑of‑file (EOF)?
Compare the return value of input functions (e.g., fgetc()) with EOF.
22. What is the difference between fgets() and fscanf()?
fgets() reads a whole line (including whitespace); fscanf() reads formatted input, skipping
whitespace.
[Link] is variable scope?
The region of the program where a variable is accessible.
24. What are the types of variable scope in C?
Local (block scope) and global (file scope).
25. What is the lifetime of a variable?
The period during which a variable exists in memory.
26. What is a local variable?
A variable declared inside a function/block; accessible only within that block.
27. What is a global variable?
A variable declared outside all functions; accessible throughout the file (or program).
28. How does storage class affect scope & lifetime?
auto (local, block lifetime), static (local with persistent lifetime), extern (global, external linkage),
register (local, suggested for CPU register).
29. What is the difference between static and extern?
static limits scope to the file/function and retains value between calls; extern extends scope to
other files.
30. Can a local variable be accessed outside its function?
No, unless its address is passed (via pointers) and accessed improperly.
31. What happens to a local variable when its function ends?
Its memory is released (for auto variables); it ceases to exist.
32. How do you declare a global variable in another file?
Use extern type var_name; in the other file.
[Link] is file handling?
Operations to create, read, write, and manage files using program instructions.
34. What is a FILE pointer?
A pointer to a FILE structure that represents an open file.