UNIT-I: INTRODUCTION
Q: Explain the basic structure of a C program with an example.
A: A basic C program structure:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
Q: Draw a flowchart to find the largest of three numbers.
A: Flowcharts can't be shown in text, but you compare a > b, a > c, etc.
Q: Differentiate between compiler and interpreter.
A: Compiler translates the whole code at once; Interpreter translates line-by-line.
Q: Write an algorithm and flowchart to calculate the factorial of a number.
A: Algorithm:
1. Start
2. Input n
3. fact = 1
4. for i=1 to n: fact *= i
5. Print fact
6. Stop
UNIT-II: OPERATORS, EXPRESSIONS, AND CONTROL STRUCTURES
Q: Explain different types of operators in C with examples.
A: Arithmetic, Relational, Logical, Bitwise, Assignment, etc.
Q: Write a program to find the largest among three numbers using if-else.
A: #include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if(a > b && a > c) printf("Largest: %d", a);
else if(b > c) printf("Largest: %d", b);
else printf("Largest: %d", c);
return 0;
Q: Explain the use of switch statement with an example.
A: int choice = 1;
switch(choice) {
case 1: printf("Option 1"); break;
default: printf("Other option");
Q: Write a program to print the Fibonacci series using a while loop.
A: int a = 0, b = 1, n = 10, temp, i = 0;
while(i < n) {
printf("%d ", a);
temp = a + b;
a = b;
b = temp;
i++;
Q: Differentiate between while, do-while, and for loops with examples.
A: while: checks condition before loop; do-while: checks after; for: compact loop form.
UNIT-III: ARRAYS AND FUNCTIONS
Q: Write a program to search an element in an array using linear search.
A: for(i = 0; i < n; i++) {
if(arr[i] == key) { printf("Found"); break; }
Q: Write a program to sort an array using bubble sort.
A: for(i = 0; i < n-1; i++)
for(j = 0; j < n-i-1; j++)
if(arr[j] > arr[j+1]) swap(arr[j], arr[j+1]);
Q: Explain the difference between call by value and call by reference with an example.
A: Call by value: copy passed; Call by reference: address passed.
Q: Write a recursive function to calculate the factorial of a number.
A: int fact(int n) {
if(n == 0) return 1;
else return n * fact(n-1);
Q: Write a program using a function to check whether a number is prime.
A: int isPrime(int n) {
for(int i = 2; i < n; i++)
if(n % i == 0) return 0;
return 1;
UNIT-IV: STRINGS AND POINTERS
Q: Write a program to reverse a string without using string library functions.
A: for(i = 0; i < len/2; i++) {
char temp = str[i];
str[i] = str[len-i-1];
str[len-i-1] = temp;
Q: What are pointers? Write a program to swap two numbers using pointers.
A: void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
Q: Explain pointer to pointer with a suitable example.
A: int a = 5; int *p = &a; int **pp = &p;
Q: Differentiate between character array and pointer to a string.
A: Array: char arr[] = "abc"; Pointer: char *ptr = "abc";
UNIT-V: STRUCTURES AND FILE HANDLING
Q: Define a structure Student with fields roll number, name, and marks.
A: struct Student {
int roll;
char name[50];
float marks;
};
Q: What is the difference between structure and union?
A: Structure: all members have memory; Union: shared memory.
Q: Write a program to open a file and count the number of characters in it.
A: FILE *fp = fopen("file.txt", "r");
int count = 0; char ch;
while((ch = fgetc(fp)) != EOF) count++;
fclose(fp);
Q: Explain file handling modes in C.
A: r, w, a, r+, w+, a+: for reading/writing/appending files.
Q: Write a program to read and write data to a file.
A: FILE *fp = fopen("data.txt", "w");
fprintf(fp, "Hello");
fclose(fp);