C Language — Exam Preparation Question Bank
Structures • Branching • Loops • Storage Classes • Preprocessor • Arrays & Pointers • Functions • Strings & Files • Memory
Structures
A college library tracks book ID, title, and price for each volume. Apply a C program using struct Book to read and display details of 3 books.
Decision Making & Branching
A shopping website offers different discounts based on the total purchase amount. Apply your knowledge of branching statements and write the suitable conditions for assigning different discount rates.
A shopping app checks the discount on a bill. Apply if-else-if and complete the code.
void main()
{
int bill = 3500;
if(bill >= 5000)
printf("20%%");
else if(________)
printf("10%%");
else
printf("5%%");
}
A shopping app gives different discounts based on the customer's purchase amount. Apply the branching concept to the given program, determine the discount displayed, and demonstrate how the conditions are evaluated.
void main()
{
int bill = 3500;
if(bill >= 5000)
printf("20%%");
else if(bill >= 3000)
printf("10%%");
else
printf("5%%");
}
A college attendance system checks a student's attendance number. It displays "Eligible" if the number is even and at least 75; otherwise, it displays "Not Eligible". Evaluate the given code, determine the output, and justify the condition that is satisfied.
void main()
{
int attendance = 78;
if(attendance >= 75)
{
if(attendance % 2 == 0)
printf("Eligible");
else
printf("Not Eligible");
}
else
printf("Not Eligible");
}
An ATM checks the PIN before withdrawal. Analyze the condition, complete the code, and interpret its working.
void main()
{
int pin = 1234;
if(________)
printf("Access");
else
printf("Invalid");
}
An ATM checks whether sufficient balance is available for withdrawal. Evaluate the condition, complete the code, and justify the result produced.
void main()
{
int balance = 5000, amount = 3000;
if(________)
printf("Success");
else
printf("Failed");
}
An ATM checks the PIN and account balance before processing a withdrawal. Analyze the situation and identify the appropriate branching structure required to handle these decisions.
A shopkeeper is developing a C program to calculate a customer's bill. Construct the basic structure of the program for this task.
Looping Constructs
A shopkeeper records the odd-numbered customers in a queue. Apply the concept of a while loop, determine the output, and describe the loop's execution.
void main()
{
int i = 1;
while(i <= 5)
{
if(i % 2 != 0)
printf("%d ", i);
i++;
}
}
A supermarket billing system repeatedly accepts item prices until the cashier enters 0. Analyze the situation and identify whether an entry-control or exit-control loop is more suitable. Justify your choice.
A college attendance system needs to display attendance percentages for 5 students. Apply the concept of looping and design the looping logic for this requirement.
Storage Classes
A web server hit-counter function resets to 1 on every page refresh instead of incrementing continuously. Inspect the variable's storage class behavior and explain why switching from auto to static fixes the bug.
A security engineer reviews a login function that stores temporary PINs in automatic local variables rather than global variables. Defend the use of the automatic storage class for sensitive, temporary function data.
Two independent billing counters in a store use local variables named billTotal inside separate functions. Trace the output of a C program showing how automatic variables maintain separate memory scopes.
Preprocessor & typedef
Two developers debate storing tax rates as a modifiable global variable versus a #define TAX_RATE 0.18 preprocessor constant. Judge which approach is safer against accidental runtime modification and why.
While maintaining legacy code, a student confuses #define PTR int* with typedef int* PTR; when declaring multiple variables. Differentiate between preprocessor macro substitution and typedef type aliasing.
A team debates hiding pointer syntax behind typedef struct Node* NodePtr; in a public library header. Assess whether hiding pointers inside a typedef improves readability or obscures memory semantics.
Arrays & Pointers
A weather station logs hourly temperatures for a 24-hour cycle. Implement a C program using a 1D array to store 24 readings and compute the daily average temperature.
Two expressions, *(arr + 3) and arr[3], access the same element in an inventory array. Correlate array subscript notation with pointer arithmetic in terms of base address and data-type scaling.
Inside a function void updateList(int data[]), sizeof(data) returns 8 bytes instead of the full 40-byte array size. Analyze why arrays decay into pointers when passed to functions in C.
A banking transaction module must swap account balances between two temporary buffers directly in memory. Code a swapBalance(float *a, float *b) function in C using pointers.
A C program declares an uninitialized pointer int *ptr; and immediately writes *ptr = 50;, causing a segmentation fault. Appraise the danger of wild pointers and determine best practices for safe pointer initialization.
A sensor calibration tool fails to update raw sensor readings inside main() after calling calibrate(rawVal). Debug the argument-passing mechanism and explain why pass-by-address is required instead of pass-by-value.
Functions & Modularity
An exam cell needs a reusable module to find the highest score in any class batch. Construct a C function findMax(int marks[], int n) that accepts an array and returns the maximum mark.
A developer wrote a 300-line monolithic main() function for a college attendance portal instead of modular functions. Analyze how breaking this code into User-Defined Functions improves readability, debugging, and reuse.
A junior programmer argues that writing separate functions slows down a small billing script and prefers keeping everything in main(). Evaluate the trade-offs between function-call overhead and software maintainability.
A student score terminal prints marks directly without passing values back:
void printScore(int marks)
{
printf("Jatasya scored %d marks!\n", marks);
}
Demonstrate the parameter and return value binding required to execute this function.
Strings & File Handling
An exam office stores student marks in marks.txt and needs to count total passing scores above 40. Calculate the pass count in C by reading the file sequentially using fscanf() until EOF.
A developer manually writes a 15-line loop to compare two strings instead of using strcmp() from <string.h>. Judge whether custom loops or standard string library functions are better for reliability and edge-case handling.
A form input handler uses strcpy(dest, src) where src is larger than dest, crashing the application. Debug the buffer overflow vulnerability and contrast strcpy() with safer bounded alternatives like strncpy().
A campus registration desk validates student usernames stored as character arrays. Trace the output of a C snippet that reads a string and counts uppercase letters until the '\0' character.
A server script opens log files inside a loop without calling fclose(), eventually failing with a "Too many open files" error. Appraise the resource-management risks of unclosed file pointers and buffer flushing failures.
A login portal verifies user passwords and formats full names by joining first and last names. Use strlen(), strcmp(), and strcat() in a C program to validate password length and merge names.
Dynamic Memory & Memory Layout
A developer uses calloc() instead of malloc() to allocate an array for a high-speed image buffer that will immediately be overwritten. Determine whether the zero-initialization overhead of calloc() is justified in this scenario.
An embedded microcontroller with only 2 KB RAM stores 10 mutually exclusive configuration payloads per device. Evaluate the memory savings of using a union versus a struct in this constrained environment.
A developer defines struct Packet { char flag; int id; }; and finds sizeof(struct Packet) is 8 bytes instead of 5 bytes. Analyze how memory alignment and structure padding explain this size difference.
A cross-platform desktop app shares binary struct dumps directly between a 32-bit ARM device and a 64-bit x86 server. Judge the portability risks of raw fwrite() dumps regarding endianness and struct padding.
Data Types & Identifiers
A health-monitoring program needs to store a body temperature of 36.5°C. Select the appropriate C data type and justify its use.
A school system uses the identifiers student_name, 123student, total_marks, and student-name. Classify them as valid or invalid identifiers with suitable justification.
A college application stores a student's age, grade, and GPA. Select the most suitable data type for each value and give a reason for each selection.
Input / Output & Formatting
A billing application must display a customer's name, item purchased, and total amount on a single receipt line with proper spacing. Construct a suitable printf() statement to produce this formatted output.
A billing application reads an item's price using:
int price;
scanf("%d", &price);
Evaluate whether this code correctly handles a price like 99.50.
A system administrator launches a backup utility from the terminal by passing the file count as an argument, while using #define MAX 100 for buffer limits. Build a C program that reads the command-line count via argv and checks it against the macro.
Operators & Expressions
A mobile recharge program calculates the final amount using recharge amount and service charge. Apply suitable arithmetic and assignment expressions to obtain the final amount.
A bus-booking program contains seats = seats - 1; after every successful booking. Analyze the statement and classify the operation performed on the variable.


If you have any doubts, Please let me know