Problem Solving in C
Complete Exam-Ready Theory Study Guide | Units 1-5
Prepared for BCom Computers Programming Exam
Unit 1: Introduction to Computer & Programming, Fundamentals of
C Programming
Q1. Define computer. Write about Characteristics & Limitations of computers.
A computer is an electronic device that accepts data (input), processes it according to a set of instructions,
and produces meaningful information (output). It can store data and retrieve it whenever needed.
Characteristics of a Computer
• Speed: A computer can process millions of instructions per second.
• Accuracy: Computers give accurate results; errors occur only due to wrong input or faulty instructions,
not due to the machine itself.
• Reliability: The output produced is consistent and dependable over long periods of use.
• Storage Capacity: A computer can store huge volumes of data in a small physical space.
• Automation: Once a program starts, it runs automatically without human intervention until it finishes.
• Diligence: A computer does not suffer from fatigue, tiredness or lack of concentration; it performs
repetitive tasks with the same accuracy every time.
• Versatility: It can perform many different kinds of tasks - calculations, data processing,
communication, design, etc.
Limitations of a Computer
• A computer has no intelligence of its own; it only follows given instructions (No IQ).
• It cannot take decisions on its own or learn from experience like a human.
• It depends entirely on the correctness of the input data and program (Garbage In, Garbage Out).
• It lacks feelings, emotions and common sense.
Q2. What are the components of a computer? (or) Draw a block diagram of computer.
A computer system is made up of the following main functional units, which together form the basic block
diagram of a computer:
• Input Unit: Accepts data and instructions from the user and converts them into machine-readable
form. Example devices: Keyboard, Mouse, Scanner.
• Central Processing Unit (CPU): The 'brain' of the computer; it processes data and controls all
operations. It has three parts - Arithmetic and Logic Unit (ALU) which performs calculations and
comparisons, Control Unit (CU) which directs the operation of all other units, and Memory/Registers
which hold data temporarily during processing.
• Memory Unit: Stores data and instructions - Primary memory (RAM/ROM) for temporary/permanent
quick-access storage, and Secondary memory (hard disk, pen drive) for permanent bulk storage.
• Output Unit: Converts the processed result into human-readable form. Example devices: Monitor,
Printer.
Flow of operation: Input Unit → CPU (Control Unit directs ALU and Memory) → Output Unit, with the Memory
Unit connected to and supporting the CPU throughout processing.
Q3. Define: Hardware & Software.
Hardware
Hardware refers to the physical, tangible components of a computer that can be seen and touched.
Examples: keyboard, mouse, monitor, CPU cabinet, printer, hard disk, RAM.
Software
Software is a set of programs and instructions that tells the hardware what to do and how to do it. It is
intangible - it cannot be touched, only used. Software is broadly of two types:
• System Software: Manages and controls hardware resources and provides a platform to run other
programs (e.g., Operating System, Device Drivers, Compilers).
• Application Software: Designed to perform specific user tasks (e.g., MS Word, browsers, games,
accounting software).
Hardware and software are interdependent - hardware without software cannot perform any task, and
software cannot run without hardware.
Q4. Define Algorithm. What are the features of Algorithms?
An algorithm is a finite, step-by-step set of well-defined instructions written in simple English/pseudo
language to solve a particular problem, arranged in a logical sequence.
Features (Characteristics) of a Good Algorithm
• Finiteness: It must terminate after a finite number of steps.
• Definiteness: Each step must be clear, precise and unambiguous.
• Input: It should have zero or more well-defined inputs.
• Output: It must produce at least one well-defined output/result.
• Effectiveness: Each step must be simple and executable in a finite amount of time.
• Language Independence: An algorithm is not written in any specific programming language, so it can
be implemented in any language.
Q5. Write about Flow charts.
A flowchart is the pictorial (diagrammatic) representation of an algorithm, using standard geometrical
symbols connected by arrows to show the sequence of steps and flow of control in a program.
Commonly Used Symbols
• Oval/Ellipse: Start / End of the program.
• Parallelogram: Input / Output operations.
• Rectangle: Processing step (calculation, assignment).
• Diamond/Rhombus: Decision-making (condition check, gives Yes/No branch).
• Arrow: Shows the direction of flow of control.
• Circle: Connector, used to join flowchart parts on the same or different pages.
Advantages
• Easy to understand the logic visually, even for a non-programmer.
• Helps in effective analysis and debugging of a problem.
• Acts as a proper program document/reference for future use.
Q6. Write about Concepts of Machine level, Assembly level and high-level
programming.
Machine Level Language (MLL)
The lowest-level language, written using only binary digits (0s and 1s). It is directly understood by the
computer's hardware, so it executes very fast, but it is extremely difficult to write, read, debug, and is
machine-dependent (differs for each processor).
Assembly Level Language (ALL)
Uses short symbolic codes called mnemonics (e.g., ADD, SUB, MOV) instead of binary numbers. It is easier
than machine language but still machine-dependent. It needs an Assembler to convert it into machine code.
High-Level Language (HLL)
Uses English-like statements and mathematical notations (e.g., C, C++, Java, Python), making it easy to
write, read and maintain. It is machine-independent (portable across different computers) but needs a
Compiler or Interpreter to translate it into machine language. Program execution is comparatively slower than
machine/assembly level languages, but development is much faster.
Q7. Write about History & Features of C Programming Language.
History
C was developed by Dennis Ritchie at Bell Laboratories (AT&T) in 1972. It evolved from earlier languages
called BCPL and B. C was originally created to re-develop the UNIX operating system. In 1988, the language
was standardized as ANSI C (American National Standards Institute) to ensure uniformity across compilers.
Features of C
• Simple and Structured: Programs are divided into small functions/modules, making the logic easy to
understand.
• Portable: A C program written on one machine can run on another with little or no modification.
• Fast (Efficient): C is close to hardware and produces compact, fast-executing programs (often called
a 'middle-level' language).
• Rich Set of Operators & Built-in Functions: Provides a large number of operators and library
functions.
• Extensible: New features and functions can be added easily by the programmer.
• Case-sensitive: Treats uppercase and lowercase letters as different.
• Supports Pointers: Allows direct manipulation of memory addresses, giving greater control.
Q8. Write about the structure of C program.
Every C program follows a fixed general structure, consisting of the following sections in order:
• Documentation Section: Comments describing the purpose of the program (written using /* */ or //);
ignored by the compiler.
• Preprocessor/Link Section: Header files are included here using #include (e.g., #include<stdio.h>),
which provide pre-defined functions.
• Definition Section: Symbolic constants can be defined here using #define.
• Global Declaration Section: Global variables and function declarations that can be used by more
than one function are placed here, outside main().
• main() Function Section: Every C program must have exactly one main() function; execution always
begins here. It is enclosed in curly braces { } and typically contains: variable declarations, executable
statements, and a return statement.
• Sub-program/User-defined Function Section: Contains definitions of any additional user-defined
functions called from main().
Q9. What are the keywords & identifiers in C programs? (or) Write about C-Tokens.
A Token is the smallest individual unit of a C program that the compiler recognizes. C has the following types
of tokens:
• Keywords: Reserved words that have a fixed, predefined meaning in C and cannot be used as
variable names. C has 32 keywords, e.g., int, float, if, else, for, while, return, struct, void.
• Identifiers: Names given by the programmer to variables, functions, arrays, etc. They must begin with
a letter or underscore, followed by letters, digits or underscores, and cannot match a keyword.
• Constants: Fixed values that do not change during execution (numeric, character, or string
constants).
• Strings: A sequence of characters enclosed in double quotes.
• Special Symbols: Symbols with special meaning such as {}, (), [], ;, comma, # etc.
• Operators: Symbols that perform operations on data, e.g., +, -, *, /, ==.
Q10. Write about data types in C.
A data type specifies the type of value a variable can hold and the amount of memory it occupies. C data
types are classified as:
Category Data Types Description
Primary/Basic int, float, char, double Fundamental built-in data types
Derived array, pointer, function Built using primary data types
User-defined structure, union, enum, typedef Created by the programmer
Void void Represents 'no value' - used for functions returning nothing
Example: int stores whole numbers, float/double store decimal (real) numbers, and char stores a single
character. Each type has a fixed memory size and range of values it can represent.
Q11. How to declare variables in C? What are the rules to construct variable names?
A variable is a named memory location used to store a value that can change during program execution.
Declaration syntax: data_type variable_name; — for example, int age; or float salary = 25000.50;
Rules for Naming Variables
• The first character must be a letter (A-Z, a-z) or an underscore (_); it cannot start with a digit.
• Only letters, digits and underscores are allowed - no spaces or special symbols (@, %, $, etc.).
• Keywords (like int, if, for) cannot be used as variable names.
• C is case-sensitive, so Sum, sum and SUM are treated as three different variables.
• No length limit is enforced practically, but only the first 31 characters are considered significant by
most compilers.
Q12. Write about I/O statements in C.
Input/Output statements are used to read data from the user and display results on the screen. The standard
header file stdio.h must be included to use them.
Formatted I/O Functions
• scanf(): Used to read formatted input from the keyboard into variables, using format specifiers (%d,
%f, %c, %s) along with the address (&) of the variable.
• printf(): Used to display formatted output on the screen, using format specifiers to print the values of
variables along with any message text.
Unformatted (Character) I/O Functions
• getchar() / putchar(): Read/display a single character.
• gets() / puts(): Read/display a complete string (line of text).
Q13. What are the operators used in a C program?
An operator is a symbol that tells the compiler to perform a specific mathematical or logical operation on
operands (data). C provides the following categories of operators:
• Arithmetic Operators: +, -, *, /, % (modulus) - used for basic mathematical calculations.
• Relational Operators: <, >, <=, >=, ==, != - used to compare two values, result is true(1) or false(0).
• Logical Operators: && (AND), || (OR), ! (NOT) - used to combine or reverse conditions.
• Assignment Operators: =, +=, -=, *=, /=, %= - used to assign or update values of a variable.
• Increment/Decrement Operators: ++ and -- - increase or decrease a variable's value by 1 (can be
used in prefix or postfix form).
• Conditional (Ternary) Operator: ?: - a short form of if-else, syntax: condition ? value_if_true :
value_if_false.
• Bitwise Operators: &, |, ^, ~, <<, >> - operate directly on the bits of data.
• Special Operators: sizeof() (gives size of a data type/variable), comma operator, and the &
(address-of) and * (value-at-address) pointer operators.
Q14. C Programming Examples.
This is a practical/lab section of the book consisting of worked example programs (e.g., simple calculations,
area/volume, temperature conversion, checking odd/even, etc.) intended for hands-on practice rather than a
written theory answer. Focus your revision here on tracing the logic and output of standard example
programs covered in class, since this section is typically tested through viva or lab exams rather than
descriptive theory questions.
Unit 2: Decision Making & Looping Statements, Jump Control
Statements
Q1. Write about conditional statements in C. [Decision Control Statements]
Decision control (conditional) statements allow a program to choose between different paths of execution
based on whether a condition is true or false.
• if statement: Executes a block of code only if the given condition is true.
• if-else statement: Executes one block if the condition is true, and a different block if it is false.
• nested if-else: An if-else statement placed inside another if or else block, used to test multiple
conditions in sequence.
• if-else-if ladder: A chain of if-else statements used to test several conditions one after another,
executing the block for the first true condition.
• switch statement: Used to select one of many possible blocks (cases) to execute, by matching the
value of an expression against multiple case labels; the optional default case runs when no match is
found and break is used to exit each case.
Q2. Write about iterative statements in C. [Looping Statements]
Looping (iterative) statements are used to repeat a block of statements multiple times until a given condition
is satisfied. C provides three types of loops:
Loop Key Point
for loop Entry-controlled loop; initialization, condition and increment/decrement are written together, ideal when the
while loop Entry-controlled loop; condition is checked first - if false at the start, the body may not execute even once.
do-while loop Exit-controlled loop; condition is checked after executing the body, so the loop always executes at least on
Q3. Write about nested loops in C.
A nested loop is a loop placed inside the body of another loop. The loop that contains another loop is called
the outer loop, and the loop inside it is the inner loop.
For every single iteration of the outer loop, the inner loop runs through its complete set of iterations. Nested
loops are commonly used for handling two-dimensional structures such as matrices, printing patterns
(triangles, pyramids of stars/numbers), and multiplication tables. Any combination of for, while and do-while
loops can be nested within each other.
Q4. How to use break, continue & goto statements in a C program?
break statement
Used to immediately terminate the loop (for/while/do-while) or switch statement in which it appears, and
transfers control to the statement immediately following it.
continue statement
Used to skip the remaining statements in the current iteration of a loop and move directly to the next iteration
(re-checking the loop condition), without exiting the loop entirely.
goto statement
An unconditional jump statement that transfers control directly to a pre-defined 'label' elsewhere in the
program. Syntax uses goto label; to jump, and label: to mark the destination. It is generally avoided in
structured programming as excessive use makes the program logic hard to follow (leads to 'spaghetti code').
Unit 3: Arrays & Strings
Q1. How to declare & access elements of an Array?
An array is a collection of elements of the same data type, stored in contiguous (continuous) memory
locations, referred to by a single common name.
Declaration
Syntax: data_type array_name[size]; — for example, int marks[5]; reserves memory for 5 integers.
Accessing Elements
Each element is accessed using an index (subscript) enclosed in square brackets, where indexing always
starts at 0. So in marks[5], valid indices are marks[0] through marks[4]. Elements can be accessed for both
reading and assigning values, typically using a for loop to process the entire array.
Q2. Write about different operations used on Arrays.
• Traversal: Visiting/accessing each element of the array once, usually using a loop, to display or
process all values.
• Insertion: Adding a new element at a specified position in the array, which requires shifting
subsequent elements to make room.
• Deletion: Removing an element from a specified position, which requires shifting subsequent
elements to fill the gap.
• Searching: Finding whether a given value exists in the array (e.g., Linear Search, Binary Search) and
locating its position.
• Sorting: Arranging the elements in a particular order - ascending or descending (e.g., Bubble Sort,
Selection Sort).
• Merging: Combining two arrays into a single array.
Q3. Write about two-dimensional arrays.
A two-dimensional (2-D) array is an array of arrays, used to represent data in a table/matrix form having rows
and columns.
Declaration syntax: data_type array_name[rows][columns]; — for example, int a[3][4]; creates an array with 3
rows and 4 columns (12 elements total).
An element is accessed using two indices - one for the row and one for the column, e.g., a[1][2] refers to the
element in the 2nd row and 3rd column (since indexing starts at 0). 2-D arrays are commonly used to
represent matrices and are typically processed using nested loops - the outer loop for rows and the inner
loop for columns.
Q4. Write a C program to multiply two matrices. (Concept/Logic - no code)
Matrix multiplication is possible only when the number of columns of the first matrix equals the number of
rows of the second matrix. If matrix A is of order m x n and matrix B is of order n x p, the resulting matrix C
will be of order m x p.
Logic (Algorithm Steps)
• Read the order (rows and columns) and elements of both matrices A and B.
• Check that the number of columns in A equals the number of rows in B; otherwise multiplication is not
possible.
• Use three nested loops: the outer two loops (i, j) iterate over the rows of A and columns of B to
determine each element position of the result matrix C, and the innermost loop (k) computes the sum
of the products of corresponding elements: C[i][j] = C[i][j] + A[i][k] * B[k][j].
• After the innermost loop completes for a given (i, j), C[i][j] holds the final value of that position.
• Repeat until all positions of C are filled, then display the resulting matrix C.
Q5. Write about 'string functions' in C.
A string in C is an array of characters terminated by the null character '\0'. The header file string.h provides
built-in functions to manipulate strings:
Function Purpose
strlen(s) Returns the length of string s (excluding the null character)
strcpy(dest, src) Copies the string src into dest
strcat(s1, s2) Appends (concatenates) string s2 to the end of string s1
strcmp(s1, s2) Compares two strings; returns 0 if equal, negative/positive value otherwise
strrev(s) Reverses the given string
strlwr(s) / strupr(s) Converts the string to lowercase / uppercase
Q6. Write about 'Character handling functions' in C.
The header file ctype.h provides built-in functions to test and convert individual characters:
Function Purpose
isalpha(c) Checks whether c is an alphabet (letter)
isdigit(c) Checks whether c is a numeric digit (0-9)
isalnum(c) Checks whether c is a letter or a digit
isspace(c) Checks whether c is a whitespace character
isupper(c) / islower(c) Checks whether c is uppercase / lowercase
toupper(c) / tolower(c) Converts c to uppercase / lowercase
Unit 4: Functions, Storage Classes, Pointers
Q1. Write about the declaration & definition of functions in C.
A function is a self-contained, reusable block of code designed to perform a specific task.
Function Declaration (Prototype)
Informs the compiler in advance about the function's name, return type, and the number/type of parameters it
takes, without giving the actual body. It is written before main() and ends with a semicolon, e.g., int add(int,
int);
Function Definition
Contains the actual body/code of the function - the complete set of statements that specify what the function
does when it is called. Syntax: return_type function_name(parameter list) { statements; return value; }
Q2. How to call functions? Write about 'return' statement in functions.
A function is called (invoked) simply by writing its name followed by parentheses containing any required
arguments, e.g., result = add(a, b);. When called, control transfers from the calling function to the called
function; once the called function finishes, control returns to the point right after the call.
The return Statement
Used inside a function to send a value back to the calling function and to immediately end the function's
execution at that point. A function can have multiple return statements (in different branches), but only one is
ever executed per call. If a function's return type is void, it either has no return statement or uses a plain
return; with no value.
Q3. How to pass parameters to the functions? (or) Explain Call By Value & Call By
Reference.
Parameters (arguments) are the values passed into a function so that it has data to work with. C supports two
methods of passing parameters:
Call by Value Call by Reference
A copy of the actual argument's value is passed to the function.
The address (location) of the actual argument is passed to the function, us
Any changes made to the parameter inside the function do
Since
NOTthe
affect
function
the original
works directly
[Link] the original memory location, changes
The formal parameter is a normal variable. The formal parameter is declared as a pointer.
Safer, since original data cannot be accidentally [Link] when the function needs to modify the caller's variables or return m
Q4. Write about the scope of variables in a C program.
Scope refers to the region/part of the program within which a variable is accessible (visible) and can be used.
• Local Variables: Declared inside a function or block; accessible only within that function/block and
destroyed once it finishes execution.
• Global Variables: Declared outside all functions, usually at the top of the program; accessible
throughout the entire program, by all functions, from the point of declaration until the program ends.
• Block Scope: A variable declared inside a pair of { } (e.g., inside an if or for block) is accessible only
within that specific block.
Q5. Write about 'recursive functions' (or) 'Recursion' in C.
Recursion is a technique in which a function calls itself, either directly or indirectly, to solve a problem by
breaking it down into smaller sub-problems of the same type.
Essential Components
• Base Case: A terminating condition that stops the recursive calls; without it, the function would call
itself infinitely, causing a stack overflow.
• Recursive Case: The part where the function calls itself with a modified (usually smaller) input,
moving progressively toward the base case.
Common examples solved using recursion include finding the factorial of a number, generating the Fibonacci
series, and computing the GCD of two numbers. Recursion often leads to shorter, more elegant code but can
use more memory and be slower than an equivalent loop, because each call is stored on the function call
stack until the base case is reached.
Q6. Write about 'storage classes' in C.
A storage class determines the scope (visibility), lifetime (how long it exists in memory), and default initial
value of a variable. C provides four storage classes:
Storage Class Scope Lifetime Default Value
auto Local (block) Within the block Garbage value
register Local (block) Within the block Garbage value
static Local, but retains value Entire program run Zero
extern Global Entire program run Zero
auto is the default storage class for local variables. register requests the compiler to store the variable in a
CPU register for faster access. static variables retain their value between successive function calls instead
of being destroyed. extern is used to declare a global variable that is defined in another file/place, making it
accessible across multiple files.
Q7. How to use pointer variables in C?
A pointer is a special variable that stores the memory address of another variable, rather than storing a data
value directly.
Key Operators
• & (Address-of operator): Returns the memory address of a variable.
• * (Dereference/Value-at-address operator): Accesses or modifies the value stored at the address a
pointer is pointing to.
Declaration syntax: data_type *pointer_name; — for example, int *p; declares p as a pointer to an integer. It
must then be assigned the address of a variable of matching type, e.g., p = &x;, after which *p can be used to
read or update the value of x indirectly. Pointers are essential for dynamic memory allocation, efficient
array/string handling, and passing arguments by reference.
Q8. Write about pointer arithmetic.
Pointer arithmetic refers to the limited set of mathematical operations that can be validly performed on pointer
variables, where the compiler automatically scales the operation according to the size of the data type the
pointer points to.
• Incrementing (p++): Moves the pointer forward to point to the next element of its type (advances by
sizeof(data_type) bytes, not just 1 byte).
• Decrementing (p--): Moves the pointer backward to the previous element.
• Addition of an integer (p + n): Moves the pointer forward by n elements.
• Subtraction of an integer (p - n): Moves the pointer backward by n elements.
• Subtracting two pointers (p2 - p1): Gives the number of elements between the two pointer positions
(both must point into the same array).
Multiplication, division, and addition of two pointers are NOT allowed in C, since they would not produce a
meaningful memory address.
Q9. How to pass pointer variables as arguments to the functions?
Passing a pointer as an argument to a function is the mechanism used to achieve Call by Reference in C.
Instead of passing the value of a variable, its address is passed using the & operator, and the receiving
function's parameter is declared as a pointer.
Inside the function, the pointer parameter can be dereferenced (using *) to directly access and modify the
original variable's value at its memory location - so any changes made inside the function are reflected back
in the caller. This technique is used when a function needs to modify the caller's variables directly, or needs
to return more than one value (since a normal function can return only one value directly).
Q10. Write about using Pointers in Arrays.
There is a close relationship between arrays and pointers in C: the name of an array itself acts as a constant
pointer to its first element (base address). So for an array int a[5];, the array name a is equivalent to &a[0].
This means array elements can be accessed either using normal index notation (a[i]) or using pointer
notation (*(a+i)), and both give the same result, since a+i internally computes the address of the i-th element
(again automatically scaled by the data type size, as in pointer arithmetic). A separate pointer variable can
also be made to point to the array, e.g., int *p = a;, after which the array can be traversed by incrementing p
in a loop instead of using an index. This close relationship is heavily used in passing arrays to functions,
since arrays are always passed by reference (as a pointer) in C, and in efficient string handling.
Unit 5: Dynamic Memory Management, Structures, Unions
Q1. Write about Dynamic memory allocation in C.
Dynamic Memory Allocation is the process of allocating (or releasing) memory to variables during program
execution (run time), rather than at compile time. It allows memory to be used efficiently, especially when the
exact amount of data needed is not known in advance. The functions are provided by the header file stdlib.h
and always work with pointers.
Function Purpose
malloc() Allocates a single block of the requested size in bytes; contains garbage (uninitialized) values
calloc() Allocates multiple blocks of memory and initializes all of them to zero
realloc() Changes (increases or decreases) the size of previously allocated memory
free() Releases (deallocates) previously allocated memory back to the system, preventing memory leaks
Dynamic allocation is especially useful for data structures whose size can grow or shrink during execution,
such as linked lists, and for arrays whose required size is only known while the program is running.
Q2. Write about 'structures' in C.
A structure is a user-defined data type that groups together variables of different data types under a single
name, allowing related pieces of data to be handled as one unit.
Declared using the struct keyword: struct StudentName { member declarations; }; A structure variable is then
created and its individual members are accessed using the dot (.) operator, e.g., student1.roll_no. If
accessed through a pointer to the structure, the arrow (->) operator is used instead. Structures are commonly
used to represent real-world records, such as details of a student, employee, or book, where each record has
several related but differently-typed attributes (e.g., name as char, roll number as int, marks as float).
Q3. Write about 'unions' in C.
A union is also a user-defined data type that groups variables of different data types together, declared using
the union keyword with syntax similar to a structure. However, unlike a structure, all members of a union
share the same single memory location, and the size of the union equals the size of its largest member. This
means only one member can hold a valid value at any given time - storing a new value into one member
overwrites the data of the others, since they occupy the same memory.
Structure vs Union
Structure Union
Each member gets its own separate memory location. All members share the same memory location.
Total memory size = sum of sizes of all members. Total memory size = size of the largest member.
All members can hold valid values simultaneously. Only one member can hold a valid value at a time.
Used when all fields need to be accessed together (e.g., a
Used
student
to save
record).
memory when only one of several fields is needed at a time.
Model Question Papers 1 & 2
The textbook lists 'Model Question Paper 1' and 'Model Question Paper 2' as a final practice section. These
are sample exam papers combining questions drawn from Units 1-5 above (short-answer and essay-type),
meant for timed self-practice rather than new theory content. Once you are confident with all the Unit 1-5
answers in this guide, attempt these model papers under exam-time conditions as your final revision step.
End of Study Guide - All the best for your exam!