Top Banner Ad
ACS101 · 2024-2538 Questions

Programming Languages — 2024-25

Section A

2 Marks Each · 12 questions
Q1a2MUnit 1 — operators (arithmetic, relational, logical)
Predicted

Define Tokens and its use in Programming language.

Tokens are the smallest meaningful units recognised by a language. C tokens include keywords, identifiers, constants, string literals and punctuation symbols. The compiler groups characters into tokens before checking grammar. Tokens make source code unambiguous and allow error messages to point to the exact part of a statement that is wrong.

Key Points

  • Smallest meaningful units
  • Examples include keywords
  • Used before grammar checking
Q1a2MUnit 1 — compilation and execution
Core Concept

What is the difference between compiler and interpreter?

A compiler translates the whole source program into an executable or object file before it runs, reporting errors during translation and usually producing faster code. An interpreter translates and executes statements one at a time, which aids debugging and portability but often runs more slowly. C is normally compiled.

Key Points

  • Compiler translates whole program
  • Interpreter runs step by step
  • C uses a compiler
Q1b2MUnit 1 — Data types
Core Concept

Differentiate between low level language and high-level language.

A low level language is close to machine instructions and hardware, using mnemonics or binary codes. It gives fine control and efficient execution but is difficult to read and port. A high level language uses English like statements and abstracts hardware details, making programs easier to write, debug and move between machines.

Key Points

  • Low level is hardware close
  • High level is abstract
  • Portability differs
Q1c2MUnit 1 — operators (arithmetic, relational, logical)
Predicted

Write the significance of Operators in Programming language.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — operators arithmetic relational logical:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Discuss the various operators used in the C programming language with examples.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Operators in C. An operator is a symbol that asks the compiler to perform an operation on one or more operands. C provides arithmetic operators for addition, subtraction, multiplication, division and remainder; relational operators for comparing values; equality operators; logical operators for combining conditions; bitwise operators for manipulating individual bits; assignment operators; increment and decrement operators; the conditional operator; and the comma and size operators. Precedence decides which operator is applied first when several appear in one expression, while associativity decides the direction of evaluation when operators have the same precedence. Multiplication and division bind more tightly than addition, and parentheses should be used whenever the intended grouping might be unclear. Logical operators work on truth values and use short circuit evaluation, so the right side is skipped when the left side already decides the result. Bitwise operators work on the binary representation: AND keeps bits set in both operands, OR keeps bits set in either, XOR keeps bits that differ, and shifts move bits left or right. The conditional operator is a compact if else expression with three operands. A good answer classifies the operators, gives a short example of each family, explains precedence and associativity, and traces one expression step by step. In tariff or pattern programs, relational and logical operators select the correct slab or decide when to print a star, so linking the operator to the decision it controls is more valuable than merely listing names. Mentioning that text replacement by a macro occurs before precedence is applied explains common surprises in output questions.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • operators (arithmetic, relational, logical)
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q1c2MUnit 1 — Input/output — scanf/printf in C
Core Concept

Explain the purpose of the scanf()scanf() and printf()printf() functions in C.

The scanf function reads formatted input from the keyboard and stores values at the addresses of variables. The printf function writes formatted text and values to the screen. Format specifiers describe the expected type, such as integer or floating point. Using the address operator with scanf is essential, while printf normally receives values.

Key Points

  • scanf reads input
  • printf writes output
  • Address operator needed for scanf
Q1d2MUnit 1 — operators (arithmetic, relational, logical)
Survival ModePredictedRepeated

What is operator precedence? Give an example.

Concept / Given Data:

Operator precedence determines the order in which operators of different types are evaluated in an expression. Operator associativity determines the order of evaluation when operators of the same precedence appear together (left-to-right or right-to-left). Together they define the exact evaluation sequence the C compiler follows.

Key Principle: Higher-precedence operators bind tighter; for equal precedence, associativity (L→R or R→L) decides grouping. The full ladder is: Unary>Multiplicative (×,÷,%)>Additive (+,−)>Relational>Equality>&&>∣∣>Assignment>Comma\text{Unary} > \text{Multiplicative } (\times, \div, \%) > \text{Additive } (+, -) > \text{Relational} > \text{Equality} > \&\& > || > \text{Assignment} > \text{Comma}

Step-by-Step Explanation with Examples:

Step 1 — Precedence Example (different operators):

Consider the expression:

a=5+3×2a = 5 + 3 \times 2

Multiplication (×\times) has higher precedence than addition (++), so the compiler groups it as:

a=5+(3×2)=5+6=11a = 5 + (3 \times 2) = 5 + 6 = 11

If we wanted addition first, we must use explicit parentheses: (5+3)×2=16(5+3)\times 2 = 16.

Step 2 — Associativity Example (same precedence, L→R):

Consider:

b=100/10/5b = 100 / 10 / 5

Both divisions have the same precedence and are left-associative, so:

b=(100/10)/5=10/5=2b = (100 / 10) / 5 = 10 / 5 = 2

If it were right-associative (it is not), the result would be 100/(10/5)=10100 / (10/5) = 10.

Step 3 — Right-associative Example (assignment):

Consider:

c=d=7c = d = 7

Assignment is right-associative, so it evaluates as:

c=(d=7)c = (d = 7)

First dd receives 77, then cc receives the value of the assignment expression, which is 77. Both cc and dd equal 77.

Step 4 — Mixed Precedence + Associativity:

e=2+3×4−6/2e = 2 + 3 \times 4 - 6 / 2

Apply precedence: ×\times and ÷\div first (left-to-right among themselves):

e=2+12−3e = 2 + 12 - 3

Then ++ and −- (left-to-right):

e=(2+12)−3=14−3=11e = (2 + 12) - 3 = 14 - 3 = 11

Precedence & Associativity Table:

Precedence Level Operators Associativity
1 (highest) !, ~, ++, --, (type) Right → Left
2 *, /, % Left → Right
3 +, - Left → Right
4 <, <=, >, >= Left → Right
5 ==, != Left → Right
6 && Left → Right
7 || Left → Right
8 =, +=, -= Right → Left
9 (lowest) , Left → Right

Result: Precedence resolves which operator acts first; associativity resolves direction among equals. Always use parentheses to make intent explicit and avoid ambiguity in exam answers.

Tip from Examiner: In 7-mark PYQs (2023-24, 2024-25, 2025-26), examiners award 2 marks for the definition, 3 marks for a correct worked example showing grouping, and 2 marks for the table or a second example. Common mistake: writing $100/10/5 = 100/(10/5) = 10$ — this violates left-associativity and loses 3 marks. Always write the intermediate grouping in parentheses before computing the final value.

Key Points

  • Precedence = order among different operators; Associativity = direction among same-precedence operators
  • Multiplicative (*, /, %) > Additive (+, -) > Relational > Equality > && > || > Assignment > Comma
  • Assignment and unary operators are right-associative; all others are left-associative
  • Example: 100/10/5 = (100/10)/5 = 2 (L-to-R), NOT 100/(10/5) = 10
  • Always use explicit parentheses to override default precedence in exam answers
Q1d2MUnit 2 — Control Statements
Core Concept

Draw the structure of Nested if else statement.

A nested if else structure places one conditional decision inside another. The outer test chooses a broad branch, and the inner test refines the choice within that branch. Each else belongs to the nearest unmatched if unless braces say otherwise. Indentation and braces make the structure readable and prevent logic errors.

Key Points

  • Decision inside decision
  • Outer and inner tests
  • Braces clarify pairing
Q1e2MUnit 2 — Loops — for
Survival ModePredictedRepeated

Find the Output of below code:

#include <stdio.h>
int main() {
    int z = 1;
    while (z <= 5) {
        if (z == 3) {
            z++;
        }
        printf("%d ", z);
        z++;
    }
    return 0;
}

The loop executes four times. The counter starts at zero and is increased after each pass, while the separate variable is increased at the start of every pass. When the counter reaches three the break statement exits the loop immediately. The final printed value is therefore four, and the update after break is not performed.

Key Points

  • Four iterations
  • Break at counter three
  • Printed result is four
Q1e2MUnit 2 — break and continue
Core Concept

Mention the use of break and continue in loops.

Break exits the nearest enclosing loop immediately and control continues after the loop. Continue skips the remaining statements in the current iteration and jumps to the next iteration. Break is useful when a search has succeeded, while continue is useful when an item fails a test and no further work is needed for that item.

Key Points

  • Break exits loop
  • Continue skips iteration
  • Different practical uses
Q1f2MUnit 2 — Recursion — factorial and Fibonacci (simple examples only) Real connect: Control flow is the brain of every program — from traffic signal logic to drone autopilot decision-making
Core Concept

Define recursion with an example.

Recursion is a technique in which a function solves a problem by calling itself with a smaller version of the same problem. It needs a base case that stops the calls and a recursive step that reduces the input. Factorial is a common example, where the factorial of a number is that number times the factorial of the previous number.

Key Points

  • Function calls itself
  • Needs base case
  • Factorial example
Q1f2MUnit 2 — Loops — for
Core Concept

Write the time complexity of Selection Sort.

Selection sort has quadratic time complexity in the average and worst cases. It scans the remaining unsorted part to find the smallest element, then swaps it into place. That scan happens for every position, giving roughly n squared comparisons. The best case still uses the same comparisons, while swaps are at most linear.

Key Points

  • Quadratic comparisons
  • Finds smallest each pass
  • Swaps are linear at most
Q1g2MUnit 1 — operators (arithmetic, relational, logical)
Core Concept

Define Macros and its use in C Programming.

A macro is a name replaced by a defined text before compilation. The preprocessor performs this substitution, so macros can define constants or short repeated expressions. They improve readability and make changes easy, but parentheses are important because text replacement can otherwise alter operator precedence and produce surprising results.

Key Points

  • Replaced before compilation
  • Useful for constants
  • Parentheses prevent precedence errors

Section B

7 Marks Each · 9 questions
Q2a7MUnit 1 — compilation and execution
Core Concept

Define Obj file. Discuss the Compilation process step by step in C Programming.

Concept / Given Data

An object file (.o) is the result of compiling a source file; it contains machine code, symbol tables, and relocation information but is not yet linked into an executable.

Key Formula / Principle

Compilation stages: Preprocessing→Compilation→Assembly→Linking\text{Preprocessing} \rightarrow \text{Compilation} \rightarrow \text{Assembly} \rightarrow \text{Linking}

Step‑by‑Step Solution / Working

  1. Preprocessing – The preprocessor handles directives (#include, #define, #ifdef). It expands macros, includes header files, and removes comments, producing a pure C source.
  2. Compilation – The compiler translates the preprocessed source into assembly language for the target architecture. It performs syntax checking, semantic analysis, and generates intermediate representation.
  3. Assembly – The assembler converts the assembly code into machine code, producing an object file (.o). The object file contains:
    • Text section: executable instructions.
    • Data section: initialized global/static variables.
    • BSS section: uninitialized data.
    • Symbol table: names of functions/variables.
    • Relocation entries: addresses to be fixed during linking.
  4. Linking – The linker combines one or more object files and libraries, resolves external symbols, and produces the final executable. It assigns final addresses, patches relocation entries, and creates the executable header.
  5. Execution – The operating system loads the executable into memory, sets up the stack, and starts program execution.

Result: The object file is an intermediate artifact that bridges source code and the final executable, containing relocatable machine code and metadata required for linking.

Tip from Examiner: For a 7‑mark answer, list the stages in order, describe what each stage produces, and explain the role of the object file. Use the arrow notation to show flow.

Key Points

  • Object file: relocatable machine code + symbol table
  • Stages: Preprocessing → Compilation → Assembly → Linking
  • Preprocessor handles macros and includes
  • Assembler outputs .o with text, data, BSS, symbols
Q2b7MUnit 1 — Structure of a C program
Core Concept

Write and explain the structure of a basic C program.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Structure of a C program:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Write and explain the structure of a basic C program.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Structure of a C program and computer architecture. A minimal C program contains preprocessing directives, global declarations and one or more functions, one of which is main where execution begins. Each function has a return type, a name, a parameter list and a body enclosed in braces. Statements end with semicolons, and comments explain intent without affecting execution. Good programs use meaningful identifiers, small functions, clear indentation and comments that describe why a step is needed. Before writing code, an algorithm lists the finite steps that solve the problem. A flowchart presents the same logic pictorially with standard symbols: an oval for start and stop, a parallelogram for input and output, a rectangle for processing, a diamond for a decision and arrows for control flow. A flowchart for the greatest of three numbers reads three values, compares the first with the second, compares the winner with the third and prints the result. At the hardware level, a digital computer has input units, a central processing unit, memory and output units connected by buses. The central processing unit contains the control unit, arithmetic and logic unit and registers. It follows stored instructions, fetches them from memory, decodes them and executes them while data moves between memory and input output devices. A good answer links the program structure to this stored program idea, because a compiled C program becomes instructions that the processor executes. Mentioning that algorithms are language independent while programs are language specific shows understanding of the relationship.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Structure of a C program
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q2b7MUnit 2 — Control Statements
Core Concept

Write a program to check the entered year is leap year or not with conditional operator.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Control Statements:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Write a program to check the entered year is leap year or not with conditional operator.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Control statements and decisions. Control statements determine the order in which statements execute. Sequential execution runs statements one after another, selection chooses among alternatives, and repetition executes a block several times. The if statement executes a block only when a condition is true, and an else branch handles the false case. Nested if else structures refine a decision inside a chosen branch. The switch statement selects a case from an integer or character expression and is readable when many values lead to distinct actions. A break statement is needed after each case to prevent fall through into the next case. Relational and logical operators build the conditions used by these statements. Prime number checking uses a loop that tests possible divisors and a flag that records whether any divisor was found. A vowel or consonant check uses a switch or a chain of comparisons. An even or odd test can use the remainder operator or a switch on the remainder. A flowchart expresses the same decisions with a diamond for each test and arrows for the true and false paths. A good answer explains the statement forms, gives one complete program, traces it with a sample input and notes the common mistake of forgetting braces or break. Mentioning that well chosen conditions and clear indentation make logic easier to verify shows practical programming discipline. A short note that nested decisions should be kept shallow prevents unreadable code.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Control Statements
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q2c7MUnit 1 — operators (arithmetic, relational, logical)
Predicted

Discuss different types of operators in C with examples.

Concept / Given Data

Operators in C are symbols that perform operations on operands. They are classified into five major categories:

  1. Arithmetic operators – + - * / % ++ --
  2. Relational operators – > < >= <= == !=
  3. Logical operators – && || !
  4. Bitwise operators – & | ^ ~ << >>
  5. Assignment operators – = += -= *= /= %= <<= >>= &= ^= |=

Each category has a distinct precedence and associativity, which determines the order of evaluation in complex expressions.

Key Formula / Principle: Result=Operand1;Operator;Operand2\text{Result} = \text{Operand}_1 ; \text{Operator} ; \text{Operand}_2

Step‑by‑Step Solution / Working

  1. Arithmetic – Example: int a = 5, b = 2; int c = a * b + 3; evaluates as c = 5*2 + 3 = 13 because * has higher precedence than +.
  2. Relational – Example: if (a > b) printf("a is greater"); yields true since 5 > 2.
  3. Logical – Example: int flag = (a > b) && (b < 10); results in flag = 1 because both sub‑expressions are true.
  4. Bitwise – Example: int d = a & b; gives d = 0 because binary 0101 & 0010 = 0000.
  5. Assignment – Example: int e = a += 3; first adds 3 to a (making a = 8) and then assigns 8 to e.

Boundary/Edge Explanation

  • Unary operators (++, --, !, ~) bind tightly to the operand and are right‑associative.
  • Division by zero is undefined; the compiler may issue a warning.
  • Mixed‑type expressions trigger implicit promotion: int + float → float.

Result:

The five operator groups enable C to express arithmetic calculations, logical decisions, bit manipulation, and value assignments. Understanding their precedence, associativity, and type promotion is essential for writing correct and efficient code.

Tip from Examiner: Mark‑split: 2 marks for listing categories, 3 marks for examples, 2 marks for precedence/associativity discussion. Avoid repeating the same example for multiple categories.

Key Points

  • Arithmetic: + - * / % ++ --
  • Relational: > < >= <= == !=
  • Logical: && || !
  • Bitwise: & | ^ ~ << >>
  • Assignment: = += -= *= /= %= <<= >>= &= ^= |=
Q2c7MUnit 3 — 1D array — declaration
Core Concept

Write the importance of array. Write a program to find the sum of two numbers using array passing to function.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — 1D array declaration:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Write the importance of array. Write a program to find the sum of two numbers using array passing to function.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Arrays, matrices and sorting. An array is a collection of fixed size, same type elements stored in consecutive memory locations and accessed by an index that starts at zero. A one dimensional array suits a list of marks or sensor readings. A two dimensional array is arranged as rows and columns and is used for matrices. Matrix multiplication uses nested loops: the outer loops choose the result position, and the inner loop accumulates the sum of products. A function can receive an array through a pointer to its first element, which allows the same operation to be applied to different arrays. Sorting arranges elements in order. Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order, so large values move toward the end. Selection sort repeatedly finds the smallest remaining element and swaps it into the next position. Insertion sort builds a sorted prefix by inserting each new element at its proper place. These simple sorts need roughly quadratic comparisons in the typical case, so they suit small data sets and teaching examples. A good answer declares the arrays, explains index bounds, gives the nested loop logic and traces a short list. It should mention that going beyond the last index is a common error and that passing the size to a function prevents out of bounds access. A note that efficient libraries exist for large data sets adds perspective.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • 1D array — declaration
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q2d7MUnit 3 — Simple operations — find max
Core Concept

Write a C program to input 10 integers in an array and find the average.

1. Definition and scope: C programs use declarations, expressions, control statements and functions to solve the stated problem.

2. Scored mechanism:

  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • Arithmetic, relational and logical operators follow fixed precedence and associativity.
  • Selection and iteration statements control the order of execution.
  • Functions and arrays organise reusable logic and related data.

3. Marking points — Simple operations find max:

C feature Purpose Example
Declaration reserves typed storage int a;
Control chooses or repeats actions if / for
Function packages reusable work return a+b;

4. Governing relation: Evaluate the given expression or statement using the declared types and C operator rules.

5. Application to the asked question: Write a C program to input 10 integers in an array and find the average.

  • Write the relevant C statement or expression.
  • Trace it with the supplied values.
  • State the resulting value or output.

Finding maximum, minimum and average. Simple numeric tasks build the foundation of programming. To find the largest of several numbers, store the first value as the current maximum, then compare every remaining value with it and replace the maximum when a larger value is found. The same idea with the opposite comparison finds the smallest value. To compute an average, add all values in a running total and divide by the count after the loop. Care is needed with integer division, because dividing an integer total by an integer count discards the fractional part. Casting one operand to a floating point type preserves the fraction. When the values are stored in an array, a loop can process them and a function can receive the array and its length. An algorithm for the greatest of three numbers reads three values, compares the first two, then compares the winner with the third and prints the result. Its flowchart uses two decision diamonds and one output box. A good answer states the algorithm in steps, gives a program, and traces it with a sample such as three, nine and five. It should explain initialising the maximum from the first element rather than from zero, because negative inputs would otherwise fail. Mentioning how the same pattern applies to sensor readings or marks connects the exercise to realistic data processing.

Result: Give the computed value or output for the stated program.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Simple operations — find max
  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • State the traced result from the given data.
  • Give the computed value or output for the stated program.
Q2d7MUnit 3 — Linear search in array. 9 C
Core Concept

Discuss the use of searching and write the program to find the number in an array using linear search.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Linear search in array 9:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Discuss the use of searching and write the program to find the number in an array using linear search.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Searching an array. Searching finds whether a desired value exists in a collection and, if so, where it is. Linear search examines elements one by one from the first position until the target is found or the array ends. It works on sorted and unsorted data, needs no extra memory and is simple to implement. Its worst case requires checking every element, so its time complexity is linear. Binary search is faster on sorted data. It compares the target with the middle element, discards the half that cannot contain the target and repeats on the remaining half. Each step roughly halves the search range, giving logarithmic time, but the array must be sorted first. A good answer defines searching, gives a clear algorithm for the chosen method, writes a loop with a found flag or an index result, and traces a small array. It should state what happens when the target is absent and avoid returning an index that looks valid but is not. Mentioning that linear search is adequate for small lists while binary search is preferred for large sorted lists shows practical judgement. A note that insertion into a sorted array has its own cost prevents the mistaken claim that binary search is always superior in every application.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Linear search in array. 9 C
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q2e7MUnit 2 — call by value
Core Concept

Describe the difference between call by value and call by reference with examples.

1. Definition and scope: C programs use declarations, expressions, control statements and functions to solve the stated problem.

2. Scored mechanism:

  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • Arithmetic, relational and logical operators follow fixed precedence and associativity.
  • Selection and iteration statements control the order of execution.
  • Functions and arrays organise reusable logic and related data.

3. Marking points — call by value:

C feature Purpose Example
Declaration reserves typed storage int a;
Control chooses or repeats actions if / for
Function packages reusable work return a+b;

4. Governing relation: Evaluate the given expression or statement using the declared types and C operator rules.

5. Application to the asked question: Describe the difference between call by value and call by reference with examples.

  • Write the relevant C statement or expression.
  • Trace it with the supplied values.
  • State the resulting value or output.

Functions and parameter passing. A function is a named block of code that performs a specific task. It has a declaration that tells the compiler its name, return type and parameter types, and a definition that supplies the body. Calling a function transfers control to that body, and a return statement sends a value back to the caller. Functions make programs modular, easier to test and easier to reuse. C programs use library functions such as printf and user defined functions written by the programmer. Parameters can be passed in different ways. In call by value, the function receives copies of the arguments, so changing a parameter inside the function does not change the caller's variable. In call by reference, simulated in C by passing addresses, the function uses pointers to access the original variables, so changes are visible after the call. A swap program illustrates the difference clearly: passing values leaves the original variables unchanged, while passing addresses exchanges them. A good answer defines a function, distinguishes declaration and definition, explains return values and compares the two parameter passing methods with a small example. It should mention that arrays are passed as pointers to their first element, which is why a function can modify array contents. Mentioning that call by value protects the caller from accidental changes while pointer passing is needed when multiple results must be returned adds judgement.

Result: Give the computed value or output for the stated program.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • call by value
  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • State the traced result from the given data.
  • Give the computed value or output for the stated program.
Q2e7MUnit 3 — Pointer — concept of address and pointer variable (concept only, not deep)
Core Concept

Explain the use and importance of Linked list in Programming.

1. Definition and scope: C programs use declarations, expressions, control statements and functions to solve the stated problem.

2. Scored mechanism:

  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • Arithmetic, relational and logical operators follow fixed precedence and associativity.
  • Selection and iteration statements control the order of execution.
  • Functions and arrays organise reusable logic and related data.

3. Marking points — Pointer concept of address and:

C feature Purpose Example
Declaration reserves typed storage int a;
Control chooses or repeats actions if / for
Function packages reusable work return a+b;

4. Governing relation: Evaluate the given expression or statement using the declared types and C operator rules.

5. Application to the asked question: Explain the use and importance of Linked list in Programming.

  • Write the relevant C statement or expression.
  • Trace it with the supplied values.
  • State the resulting value or output.

Pointers and dynamic memory. Every variable occupies a memory location with an address. A pointer is a variable that stores such an address. Declaring a pointer states the type of value it points to, and the address operator obtains the address of a variable. The dereference operator accesses or changes the value stored at that address. A pointer to pointer stores the address of another pointer and is useful when a function must change the pointer itself rather than the value it points to. Linked lists rely on self referential structures whose members include a pointer to the next node. Static allocation fixes memory size at compile time, while dynamic allocation requests memory at run time from the heap. The malloc function allocates a specified number of bytes and returns a pointer, calloc allocates and clears a block, realloc changes an existing block, and free returns it to the pool. Dynamic allocation avoids wasting memory when the amount of data is unknown, but it requires checking for failure and releasing every block. A good answer defines address and pointer, explains declaration and dereferencing, gives a small linked node and describes allocation with checks. It should state that using an uninitialised pointer or a freed pointer is dangerous. Mentioning that pointer arithmetic depends on the pointed type explains why a pointer must be typed correctly.

Result: Give the computed value or output for the stated program.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Pointer — concept of address and pointer variable (concept only, not deep)
  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • State the traced result from the given data.
  • Give the computed value or output for the stated program.

Section C

7 Marks Each · 17 questions
Q3a7MUnit 1 — Structure of a C program
Core Concept

Draw and discuss the architecture of Digital Computer System and its use in programming.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Structure of a C program:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Draw and discuss the architecture of Digital Computer System and its use in programming.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input. Diagram instruction: Draw the labelled figure/flow described above with inputs, control path, and output.

Structure of a C program and computer architecture. A minimal C program contains preprocessing directives, global declarations and one or more functions, one of which is main where execution begins. Each function has a return type, a name, a parameter list and a body enclosed in braces. Statements end with semicolons, and comments explain intent without affecting execution. Good programs use meaningful identifiers, small functions, clear indentation and comments that describe why a step is needed. Before writing code, an algorithm lists the finite steps that solve the problem. A flowchart presents the same logic pictorially with standard symbols: an oval for start and stop, a parallelogram for input and output, a rectangle for processing, a diamond for a decision and arrows for control flow. A flowchart for the greatest of three numbers reads three values, compares the first with the second, compares the winner with the third and prints the result. At the hardware level, a digital computer has input units, a central processing unit, memory and output units connected by buses. The central processing unit contains the control unit, arithmetic and logic unit and registers. It follows stored instructions, fetches them from memory, decodes them and executes them while data moves between memory and input output devices. A good answer links the program structure to this stored program idea, because a compiled C program becomes instructions that the processor executes. Mentioning that algorithms are language independent while programs are language specific shows understanding of the relationship.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Digital computer architecture input unit CPU output unit memory unit control unit and arithmetic logic unit share registers and buses stored program instructions are fetched, decoded and executed
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Structure of a C program
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q3b7MUnit 1 — variables
Core Concept

Write the four storage classes used in C programming with example.

Concept / Given Data

The C language defines four storage‑class specifiers that determine the lifetime, visibility and storage allocation of variables. They are:

  1. auto – default for local variables inside a block. Storage is automatic and the variable is destroyed when the block exits.
  2. register – suggests that the compiler store the variable in a CPU register for faster access. The variable still has automatic storage duration but the compiler may ignore the hint.
  3. static – gives the variable static storage duration. It is allocated once, retains its value between function calls, and is initialised only once.
  4. extern – declares a variable defined in another translation unit. It has external linkage and the storage is allocated in the defining file.

Key Formula / Principle

<div class='formula-box'><strong>Key Formula / Principle:</strong> 

$$
\text{Storage Class} \rightarrow \begin{cases}
\text{auto} &\text{automatic, block scope}\n\text{register} &\text{automatic, register hint}\n\text{static} &\text{static duration, block or file scope}\n\text{extern} &\text{external linkage, file scope}
\end{cases}
$$

</div>

Step‑by‑Step Solution / Working

  1. auto – Example:

    void func() {
        auto int a = 5;   // same as int a = 5;
    }
    

    The variable a exists only while func() is executing.

  2. register – Example:

    void loop() {
        register int i;
        for(i=0;i<10;i++) {
            /* use i */
        }
    }
    

    The compiler may place i in a register; the programmer cannot take its address.

  3. static – Example:

    void counter() {
        static int count = 0;   // initialised once
        count++;
        printf("%d\n", count);
    }
    

    Each call to counter() prints an incremented value because count persists.

  4. extern – Example:

    /* file1.c */
    int global = 10;
    /* file2.c */
    extern int global;   // declaration
    printf("%d", global);   // uses the same variable
    

    The extern keyword tells the compiler that the storage is defined elsewhere.

Result: The four storage classes—auto, register, static, and extern—control variable lifetime, scope, and storage. They are essential for managing memory and linkage in C programs.

Tip from Examiner: For a 7‑mark answer, start with a concise definition of each class, give a short code snippet, and explain the effect on lifetime and scope. Avoid repeating the same example for two classes; use distinct contexts (function, loop, file). Remember that `extern` is a declaration, not a definition.

Key Points

  • auto – automatic, block scope
  • register – CPU register hint, automatic
  • static – static duration, retains value
  • extern – external linkage, defined elsewhere
Q4a7MUnit 1 — operators (arithmetic, relational, logical)
PredictedRepeated

Explain the use of logical and bitwise operators with examples.

Concept / Given Data

Logical operators (&&, ||, !) evaluate Boolean expressions and short‑circuit, whereas bitwise operators (&, |, ^, ~, <<, >>) perform bit‑level manipulation on integer operands. Logical operators return 0 (false) or 1 (true). Bitwise operators work on the binary representation of the operands.

Key Formula / Principle: a&b,a∣b,ab, a,a<<n,a>>na \& b, a | b, a ^ b, ~a, a<<n, a>>n

Step‑by‑Step Solution / Derivation / Working

  1. Logical AND (&&) – evaluates left operand; if false, right operand is not evaluated.

    int x = 5, y = 0;
    if (x>0 && y>0) printf("both positive");
    

    Here y>0 is not evaluated because x>0 is true but y>0 is false, resulting in the condition being false.

  2. Logical OR (||) – evaluates left operand; if true, right operand is skipped.

    if (x>0 || y>0) printf("at least one positive");
    

    Since x>0 is true, y>0 is not checked.

  3. Logical NOT (!) – inverts Boolean value.

    if (!(x==5)) printf("x is not 5");
    
  4. Bitwise AND (&) – performs AND on each bit.

    int a = 0b1100, b = 0b1010; // 12 and 10
    int r = a & b; // 0b1000 = 8
    
  5. Bitwise OR (|) – performs OR on each bit.

    int r = a | b; // 0b1110 = 14
    
  6. Bitwise XOR (^) – exclusive OR.

    int r = a ^ b; // 0b0110 = 6
    
  7. Bitwise NOT (~) – flips all bits.

    int r = ~a; // 0b0011 (in 4‑bit view) = -13 in two's complement
    
  8. Left Shift (<<) – multiplies by powers of two.

    int r = a << 1; // 0b11000 = 24
    
  9. Right Shift (>>) – divides by powers of two (arithmetic shift for signed).

    int r = a >> 1; // 0b0110 = 6
    

Diagram (optional):

flowchart TD
  A[Logical AND] --> B[Short‑circuit]
  A --> C[Returns 0/1]
  D[Bitwise AND] --> E[Bit‑level AND]
  D --> F[Returns integer]

Result: Logical operators are used for control flow and decision making, yielding Boolean values, while bitwise operators manipulate individual bits of integer data, useful in low‑level programming and embedded systems.

Tip from Examiner: Remember that logical operators short‑circuit; bitwise operators do not. Also, logical operators always yield `0` or `1`, whereas bitwise operators preserve the operand type.

Key Points

  • Logical operators return 0/1 and short‑circuit
  • Bitwise operators work on binary representation
  • && skips right side if left is false
  • || skips right side if left is true
  • ! inverts Boolean value
  • &, |, ^, ~, <<, >> manipulate bits
Q4a7MUnit 1 — operators (arithmetic, relational, logical)
Predicted

Discuss the various operators used in the C programming language with examples.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — operators arithmetic relational logical:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Discuss the various operators used in the C programming language with examples.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Operators in C. An operator is a symbol that asks the compiler to perform an operation on one or more operands. C provides arithmetic operators for addition, subtraction, multiplication, division and remainder; relational operators for comparing values; equality operators; logical operators for combining conditions; bitwise operators for manipulating individual bits; assignment operators; increment and decrement operators; the conditional operator; and the comma and size operators. Precedence decides which operator is applied first when several appear in one expression, while associativity decides the direction of evaluation when operators have the same precedence. Multiplication and division bind more tightly than addition, and parentheses should be used whenever the intended grouping might be unclear. Logical operators work on truth values and use short circuit evaluation, so the right side is skipped when the left side already decides the result. Bitwise operators work on the binary representation: AND keeps bits set in both operands, OR keeps bits set in either, XOR keeps bits that differ, and shifts move bits left or right. The conditional operator is a compact if else expression with three operands. A good answer classifies the operators, gives a short example of each family, explains precedence and associativity, and traces one expression step by step. In tariff or pattern programs, relational and logical operators select the correct slab or decide when to print a star, so linking the operator to the decision it controls is more valuable than merely listing names. Mentioning that text replacement by a macro occurs before precedence is applied explains common surprises in output questions.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • operators (arithmetic, relational, logical)
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q4b7MUnit 2 — Control Statements
Core Concept

Write a C program to check whether a number is even or odd using switch case.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Control Statements:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Write a C program to check whether a number is even or odd using switch case.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Control statements and decisions. Control statements determine the order in which statements execute. Sequential execution runs statements one after another, selection chooses among alternatives, and repetition executes a block several times. The if statement executes a block only when a condition is true, and an else branch handles the false case. Nested if else structures refine a decision inside a chosen branch. The switch statement selects a case from an integer or character expression and is readable when many values lead to distinct actions. A break statement is needed after each case to prevent fall through into the next case. Relational and logical operators build the conditions used by these statements. Prime number checking uses a loop that tests possible divisors and a flag that records whether any divisor was found. A vowel or consonant check uses a switch or a chain of comparisons. An even or odd test can use the remainder operator or a switch on the remainder. A flowchart expresses the same decisions with a diamond for each test and arrows for the true and false paths. A good answer explains the statement forms, gives one complete program, traces it with a sample input and notes the common mistake of forgetting braces or break. Mentioning that well chosen conditions and clear indentation make logic easier to verify shows practical programming discipline. A short note that nested decisions should be kept shallow prevents unreadable code.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Control Statements
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q4b7MUnit 3 — Simple operations — find max
Core Concept

Write a C program to find largest number from four given numbers.

1. Definition and scope: C programs use declarations, expressions, control statements and functions to solve the stated problem.

2. Scored mechanism:

  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • Arithmetic, relational and logical operators follow fixed precedence and associativity.
  • Selection and iteration statements control the order of execution.
  • Functions and arrays organise reusable logic and related data.

3. Marking points — Simple operations find max:

C feature Purpose Example
Declaration reserves typed storage int a;
Control chooses or repeats actions if / for
Function packages reusable work return a+b;

4. Governing relation: Evaluate the given expression or statement using the declared types and C operator rules.

5. Application to the asked question: Write a C program to find largest number from four given numbers.

  • Write the relevant C statement or expression.
  • Trace it with the supplied values.
  • State the resulting value or output.

Finding maximum, minimum and average. Simple numeric tasks build the foundation of programming. To find the largest of several numbers, store the first value as the current maximum, then compare every remaining value with it and replace the maximum when a larger value is found. The same idea with the opposite comparison finds the smallest value. To compute an average, add all values in a running total and divide by the count after the loop. Care is needed with integer division, because dividing an integer total by an integer count discards the fractional part. Casting one operand to a floating point type preserves the fraction. When the values are stored in an array, a loop can process them and a function can receive the array and its length. An algorithm for the greatest of three numbers reads three values, compares the first two, then compares the winner with the third and prints the result. Its flowchart uses two decision diamonds and one output box. A good answer states the algorithm in steps, gives a program, and traces it with a sample such as three, nine and five. It should explain initialising the maximum from the first element rather than from zero, because negative inputs would otherwise fail. Mentioning how the same pattern applies to sensor readings or marks connects the exercise to realistic data processing.

Result: Give the computed value or output for the stated program.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Simple operations — find max
  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • State the traced result from the given data.
  • Give the computed value or output for the stated program.
Q5a7MUnit 2 — Loops — for
Survival ModePredictedRepeated

Write a program to print the pattern: *

  • *




1. Definition and scope: C programs use declarations, expressions, control statements and functions to solve the stated problem.

2. Scored mechanism:

  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • Arithmetic, relational and logical operators follow fixed precedence and associativity.
  • Selection and iteration statements control the order of execution.
  • Functions and arrays organise reusable logic and related data.

3. Marking points — Loops for:

C feature Purpose Example
Declaration reserves typed storage int a;
Control chooses or repeats actions if / for
Function packages reusable work return a+b;

4. Governing relation: Evaluate the given expression or statement using the declared types and C operator rules.

5. Application to the asked question: Write a program to print the following pattern in C: **** *** ** *

  • Write the relevant C statement or expression.
  • Trace it with the supplied values.
  • State the resulting value or output.

Loops in C. A loop repeats a block of statements while a condition remains true. The for loop places initialisation, condition and update together in one header, which suits situations where the number of iterations is known. The while loop tests the condition before each iteration, so the body may run zero times. The do while loop tests after the body, so it runs at least once. Every loop needs an update that moves the condition toward false, otherwise it never terminates. The break statement exits the nearest loop immediately, while continue skips the rest of the current iteration and proceeds to the next one. Nested loops are used for patterns and tables: the outer loop controls rows and the inner loop controls columns. For a descending star pattern, the number of stars decreases each row, so the inner limit depends on the row counter. Loop analysis also leads to time complexity. A loop that halves its input each time is logarithmic, a single pass is linear, and nested passes over the same data are quadratic. A good answer declares the loop variables, explains each header part, traces a short example and states the output. It should mention the risk of an off by one error, because starting at zero or stopping at the wrong bound changes the printed values. Mentioning that break can simplify a search once the item is found gives a practical use.

Result: Give the computed value or output for the stated program.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Loops — for
  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • State the traced result from the given data.
  • Give the computed value or output for the stated program.
Q5a7MUnit 3 — Strings in C — gets/puts
Core Concept

Write a C program to reverse a string entered by the user.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Strings in C gets puts:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Write a C program to reverse a string entered by the user.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Strings in C. A string in C is an array of characters terminated by a null character. The terminator marks the end of the text, so the array must have one extra element beyond the visible characters. Strings can be initialised with a character list or a quoted literal, and functions such as strlen, strcpy, strcat and strcmp operate on them. The gets function reads a line until a newline and stores a terminator, while puts prints a string followed by a newline. Because gets does not check buffer size, modern code prefers fgets to avoid overflow. Reversing a string is a standard array exercise. One approach finds the length, then swaps the first character with the last, the second with the second last and so on until the pointers meet in the middle. Another approach copies characters from the end into a second array and appends a terminator. A good answer defines the null terminator, shows a declaration, explains one library function and gives the loop used for reversal. It should trace a short word so the swapping pattern is clear. Mentioning that writing past the array or forgetting the terminator causes unpredictable output highlights the common mistakes. A note that strings are really character arrays explains why array indexing works on them.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Strings in C — gets/puts
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q5b7MUnit 3 — Structures
Survival ModePredicted

What is a structure in C? Give an example of an array of structures.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Structures:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: What is a structure in C? Give an example of an array of structures.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Structures, unions and linked data. A structure is a user defined type that groups related members which may have different types. It is declared with a tag and variables of that type can be created individually or as an array. Members are accessed with the dot operator, or with the arrow operator when working through a pointer. An array of structures is useful for records such as students or employees, where each element holds a name, designation, salary, department and city. A program can scan such an array and print only records whose salary exceeds a chosen limit. A union resembles a structure but all members share the same memory, so only one member can hold a valid value at a time. It saves space when alternatives are exclusive, for example storing different kinds of student information in one record. A self referential structure contains a pointer to another structure of the same type, which is the basis of a linked list. Each node holds data and a link to the next node, and a head pointer identifies the start. A good answer defines each term, gives a declaration, explains member access and shows a small traversal. It should state the difference between structure and union in terms of memory allocation and valid members. Mentioning that dynamic allocation allows a linked list to grow during execution connects the idea to practical programming.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Structures
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q5b7MUnit 3 — 1D array — declaration
Core Concept

Write a Program to find the multiplication of two n×nn \times n matrix.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — 1D array declaration:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Write a Program to find the multiplication of two n \times n matrix.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Arrays, matrices and sorting. An array is a collection of fixed size, same type elements stored in consecutive memory locations and accessed by an index that starts at zero. A one dimensional array suits a list of marks or sensor readings. A two dimensional array is arranged as rows and columns and is used for matrices. Matrix multiplication uses nested loops: the outer loops choose the result position, and the inner loop accumulates the sum of products. A function can receive an array through a pointer to its first element, which allows the same operation to be applied to different arrays. Sorting arranges elements in order. Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order, so large values move toward the end. Selection sort repeatedly finds the smallest remaining element and swaps it into the next position. Insertion sort builds a sorted prefix by inserting each new element at its proper place. These simple sorts need roughly quadratic comparisons in the typical case, so they suit small data sets and teaching examples. A good answer declares the arrays, explains index bounds, gives the nested loop logic and traces a short list. It should mention that going beyond the last index is a common error and that passing the size to a function prevents out of bounds access. A note that efficient libraries exist for large data sets adds perspective.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • 1D array — declaration
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q6a7MUnit 2 — Recursion — factorial and Fibonacci (simple examples only) Real connect: Control flow is the brain of every program — from traffic signal logic to drone autopilot decision-making
Predicted

Write a recursive C program to find the nthn^{th} Fibonacci number.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Recursion factorial and Fibonacci simple:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Write a recursive C program to find the n^{th} Fibonacci number.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Recursion and base cases. Recursion occurs when a function calls itself to solve a smaller instance of the same problem. It is useful when a problem is naturally defined in terms of a simpler version of itself, such as factorial, Fibonacci numbers or processing digits. Every recursive function needs two parts. The base case gives a direct answer for the smallest input and stops the chain of calls. The recursive case expresses the answer in terms of a call with a reduced input, so the problem moves toward the base case. Without a reachable base case, calls continue until the call stack is exhausted. Each call has its own local variables and return address stored on the stack, so recursion uses more memory than an equivalent loop. Factorial of zero or one is the base value one, and factorial of a larger number is that number multiplied by the factorial of the previous number. Fibonacci numbers use two base values and sum the two previous terms. A recursive digit product multiplies the last digit by the product of the remaining digits. A good answer defines recursion, identifies the base and recursive cases in the given program, traces a small input and explains the output. It should also state that recursion often gives shorter, clearer code but may be slower because of function call overhead. Mentioning that iteration can avoid stack growth shows a balanced understanding of the tradeoff.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Recursion — factorial and Fibonacci (simple examples only) Real connect: Control flow is the brain of every program — from traffic signal logic to drone autopilot decision-making
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q6a7MUnit 3 — 1D array — declaration
Core Concept

Write a Program to sort the given list of data using bubble sort and compare its time complexity with insertion sort. Data: 7, 3, 8, 5, 9, 2, 4, 6

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — 1D array declaration:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Write a Program to sort the given list of data using bubble sort and compare its time complexity with insertion sort. Data: 7, 3, 8, 5, 9, 2, 4, 6

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Arrays, matrices and sorting. An array is a collection of fixed size, same type elements stored in consecutive memory locations and accessed by an index that starts at zero. A one dimensional array suits a list of marks or sensor readings. A two dimensional array is arranged as rows and columns and is used for matrices. Matrix multiplication uses nested loops: the outer loops choose the result position, and the inner loop accumulates the sum of products. A function can receive an array through a pointer to its first element, which allows the same operation to be applied to different arrays. Sorting arranges elements in order. Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order, so large values move toward the end. Selection sort repeatedly finds the smallest remaining element and swaps it into the next position. Insertion sort builds a sorted prefix by inserting each new element at its proper place. These simple sorts need roughly quadratic comparisons in the typical case, so they suit small data sets and teaching examples. A good answer declares the arrays, explains index bounds, gives the nested loop logic and traces a short list. It should mention that going beyond the last index is a common error and that passing the size to a function prevents out of bounds access. A note that efficient libraries exist for large data sets adds perspective.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • 1D array — declaration
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q6b7MUnit 2 — Functions — definition
Core Concept

Define call by reference. Write a program to swap two numbers with this concept.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Functions definition:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Define call by reference. Write a program to swap two numbers with this concept.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Functions and parameter passing. A function is a named block of code that performs a specific task. It has a declaration that tells the compiler its name, return type and parameter types, and a definition that supplies the body. Calling a function transfers control to that body, and a return statement sends a value back to the caller. Functions make programs modular, easier to test and easier to reuse. C programs use library functions such as printf and user defined functions written by the programmer. Parameters can be passed in different ways. In call by value, the function receives copies of the arguments, so changing a parameter inside the function does not change the caller's variable. In call by reference, simulated in C by passing addresses, the function uses pointers to access the original variables, so changes are visible after the call. A swap program illustrates the difference clearly: passing values leaves the original variables unchanged, while passing addresses exchanges them. A good answer defines a function, distinguishes declaration and definition, explains return values and compares the two parameter passing methods with a small example. It should mention that arrays are passed as pointers to their first element, which is why a function can modify array contents. Mentioning that call by value protects the caller from accidental changes while pointer passing is needed when multiple results must be returned adds judgement.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Functions — definition
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q7a7MUnit 1 — compilation and execution
Core Concept

Define DMA. Write a program to allocate the run time memory and find the sum of all the numbers entered by the user within that memory.

Tip from Examiner: Define the key term first, explain the mechanism with one concrete example, and close with the control or legal provision that applies to it.
**Concept / Given Data**

Define DMA (Direct Memory Access) as a feature that allows peripheral devices to transfer data directly to/from main memory without continuous CPU intervention. In a C program, dynamic memory allocation is typically performed using the malloc or calloc functions, which request a block of memory from the heap at run time.

Key Formula / Principle

<div class='formula-box'><strong>Key Formula / Principle:</strong> 

$$
\text{size\_t }\text{malloc}(\text{size\_t }\text{size})
$$

</div>

Step‑by‑Step Solution

  1. Include required headers: #include <stdio.h> for I/O and #include <stdlib.h> for malloc.
  2. Prompt user for number of elements: int n; printf("Enter number of elements: "); scanf("%d", &n);.
  3. Allocate memory: int *arr = (int *)malloc(n * sizeof(int)); – this reserves n integers.
  4. Check allocation: if (arr == NULL) { perror("malloc failed"); exit(EXIT_FAILURE); }.
  5. Read values: Loop for (int i = 0; i < n; ++i) { printf("Enter element %d: ", i+1); scanf("%d", &arr[i]); }.
  6. Compute sum: int sum = 0; for (int i = 0; i < n; ++i) sum += arr[i];.
  7. Display result: printf("Sum of entered numbers = %d\n", sum);.
  8. Free memory: free(arr); to release the heap block.

Result

The program dynamically allocates memory for n integers, reads them from the user, calculates their sum, prints the sum, and finally frees the allocated memory. This demonstrates the use of DMA‑style memory allocation in C.

Exam‑Tip

  • Remember to cast the return of malloc to the appropriate pointer type.
  • Always check for NULL before using the pointer.
  • Use sizeof(*arr) instead of sizeof(int) for portability.

Key Points

  • DMA allows peripherals to bypass CPU for memory transfer.
  • malloc returns a void* that must be cast.
  • Always free allocated memory to avoid leaks.
  • Check for NULL to handle allocation failure.
  • Use sizeof(*ptr) for type‑agnostic sizing.

Key Points

  • DMA bypasses CPU for memory transfer
  • malloc returns void* that must be cast
  • Always check for NULL before use
  • Free memory with free() to avoid leaks
  • Use sizeof(*ptr) for portability
Q7a7MUnit 3 — File Handling Real connect: Arrays store sensor readings
Predicted

Write a C program to read and display contents of a file.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — File Handling Real connect Arrays:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Write a C program to read and display contents of a file.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

File handling in C. A file is a named collection of data stored on a device. C treats a file as a stream of bytes and uses a file pointer of type FILE to manage it. Before reading or writing, the file must be opened with a mode that states the intended operation. Read mode opens an existing file for input, write mode creates a new file or empties an existing one, append mode adds at the end, and update modes allow both reading and writing. Text mode translates line endings, while binary mode preserves bytes exactly. Functions such as fgetc and fputc handle one character, fgets and fputs handle lines, and fprintf and fscanf handle formatted data. The feof function reports that a previous read tried to move past the end, so it should be checked after a read rather than used as the loop condition alone. A file used for input or output must be closed with fclose so buffers are flushed and resources are released. Common tasks include copying one file to another, counting vowels in a text file and displaying file contents. A good answer defines a file, lists the opening modes, explains at least three functions and gives a loop that reads until end of file. It should mention error handling, because a failed open returns a null pointer. A note that buffered input output improves speed explains why closing the file matters.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • File Handling Real connect: Arrays store sensor readings
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q7b7MUnit 3 — Structures
Predicted

Explain self-referential structures and their use in linked list.

1. Definition and scope: C constructs provide the vocabulary for representing data and controlling execution: declarations define storage, operators transform values, and control statements choose the path of computation.

2. Scored mechanism:

  • A data type fixes the set of legal values and operations, such as int, float, char, string, or list.
  • Arithmetic, relational, logical, and bitwise operators have distinct precedence and associativity.
  • Selection statements use conditions; iteration statements repeat a block until a termination condition is met.
  • Functions accept parameters, return values, and reduce duplication through modular decomposition.
  • Recursion solves a problem by calling itself on a smaller instance with a clear base case.
  • Arrays store homogeneous elements in contiguous memory addressable by an index; Python lists are dynamic.

3. Marking points — Structures:

Construct Purpose Example
Sequence execute in order assignments
Selection choose a branch if / else
Iteration repeat a block for / while
Function reuse logic def / return

4. Procedure:

  1. Identify the base definition needed for the question.
  2. Apply the relevant rule or formula to the given values.
  3. Trace each step with the given input.
  4. State the final value.

5. Application to the asked question: Explain self-referential structures and their use in linked list.

  • Identify the base definition needed for the question.
  • Apply the relevant rule or formula to the given values.
  • Trace each step with the given input.

Structures, unions and linked data. A structure is a user defined type that groups related members which may have different types. It is declared with a tag and variables of that type can be created individually or as an array. Members are accessed with the dot operator, or with the arrow operator when working through a pointer. An array of structures is useful for records such as students or employees, where each element holds a name, designation, salary, department and city. A program can scan such an array and print only records whose salary exceeds a chosen limit. A union resembles a structure but all members share the same memory, so only one member can hold a valid value at a time. It saves space when alternatives are exclusive, for example storing different kinds of student information in one record. A self referential structure contains a pointer to another structure of the same type, which is the basis of a linked list. Each node holds data and a link to the next node, and a head pointer identifies the start. A good answer defines each term, gives a declaration, explains member access and shows a small traversal. It should state the difference between structure and union in terms of memory allocation and valid members. Mentioning that dynamic allocation allows a linked list to grow during execution connects the idea to practical programming.

Result: State the traced result from the given data.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Structures
  • A data type fixes the set of legal values and operations, su
  • Arithmetic, relational, logical, and bitwise operators have
  • Selection statements use conditions; iteration statements re
  • Functions accept parameters, return values, and reduce dupli
  • State the traced result from the given data.
Q7b7MUnit 3 — Pointer — concept of address and pointer variable (concept only, not deep)
Core Concept

Define Pointer. Discuss the self referential pointer with example.

1. Definition and scope: C programs use declarations, expressions, control statements and functions to solve the stated problem.

2. Scored mechanism:

  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • Arithmetic, relational and logical operators follow fixed precedence and associativity.
  • Selection and iteration statements control the order of execution.
  • Functions and arrays organise reusable logic and related data.

3. Marking points — Pointer concept of address and:

C feature Purpose Example
Declaration reserves typed storage int a;
Control chooses or repeats actions if / for
Function packages reusable work return a+b;

4. Governing relation: Evaluate the given expression or statement using the declared types and C operator rules.

5. Application to the asked question: Define Pointer. Discuss the self referential pointer with example.

  • Write the relevant C statement or expression.
  • Trace it with the supplied values.
  • State the resulting value or output.

Pointers and dynamic memory. Every variable occupies a memory location with an address. A pointer is a variable that stores such an address. Declaring a pointer states the type of value it points to, and the address operator obtains the address of a variable. The dereference operator accesses or changes the value stored at that address. A pointer to pointer stores the address of another pointer and is useful when a function must change the pointer itself rather than the value it points to. Linked lists rely on self referential structures whose members include a pointer to the next node. Static allocation fixes memory size at compile time, while dynamic allocation requests memory at run time from the heap. The malloc function allocates a specified number of bytes and returns a pointer, calloc allocates and clears a block, realloc changes an existing block, and free returns it to the pool. Dynamic allocation avoids wasting memory when the amount of data is unknown, but it requires checking for failure and releasing every block. A good answer defines address and pointer, explains declaration and dereferencing, gives a small linked node and describes allocation with checks. It should state that using an uninitialised pointer or a freed pointer is dangerous. Mentioning that pointer arithmetic depends on the pointed type explains why a pointer must be typed correctly.

Result: Give the computed value or output for the stated program.

Tip from Examiner: State the concept, show the C code or flowchart with clear comments, trace one sample input, and mention the common mistake or boundary condition an examiner will look for.
Key Formula / Principle: $O(1)$ $\&$ $a\& b, a|b, a^b$

Key Points

  • Pointer — concept of address and pointer variable (concept only, not deep)
  • Identify the declared types and values before applying the operator.
  • Apply C precedence and associativity when an expression has several operators.
  • Match the format specifier or file mode to the data being handled.
  • State the traced result from the given data.
  • Give the computed value or output for the stated program.