Top Banner Ad
ACS101 · 2023-2444 Questions

Programming Languages — 2023-24

Section A

2 Marks Each · 14 questions
Q1a2MUnit 1 — Data types
Core Concept

1 Nibble = ……….. Bytes.

A nibble is a group of four bits. Since one byte contains eight bits, one nibble is half a byte. It is often used when describing hexadecimal digits because each hexadecimal digit represents exactly four binary bits, so two hexadecimal digits represent one complete byte.

Key Points

  • Four bits
  • Half of one byte
  • One hexadecimal digit
Q1a2MUnit 1 — Structure of a C program
Core Concept

Define Syntax. Write the importance of Syntax in programming.

Syntax is the set of grammatical rules that define which source code statements are valid in a language. It matters because the compiler can translate only correctly formed statements. A missing semicolon, mismatched brace or wrong declaration stops compilation, so attention to syntax turns an idea into an executable program and prevents wasted debugging time.

Key Points

  • Grammar of language
  • Compiler checks it
  • Errors stop compilation
Q1b2MUnit 1 — operators (arithmetic, relational, logical)
Core Concept

Find the value of variable max in the following code: - int a=10, b=20; int max=(a>b)? a: b;

The conditional operator tests the condition before choosing a value. Since ten is less than twenty, the expression selects the first value and assigns ten to the variable named max. The result is therefore ten, and the comparison itself does not change either original variable.

Key Points

  • Condition is true
  • First value selected
  • Result is ten
Q1b2MUnit 1 — Structure of a C program
Core Concept

Draw the Memory Hierarchy according to the Access time.

Memory hierarchy arranges storage by speed, cost and capacity. Registers are fastest and smallest, followed by cache, main memory, solid state storage and magnetic or optical storage. Slower levels are larger and cheaper per bit. Programs benefit when frequently used data stays near the processor because access time strongly affects performance.

Key Points

  • Ordered by speed and cost
  • Registers fastest
  • Cache before main memory
Q1c2MUnit 1 — Type conversion
Survival ModeRepeated

Define Explicit type conversion with suitable example.

Implicit conversion is performed automatically by the compiler when a value is assigned to a wider compatible type. Explicit conversion, called casting, is requested by the programmer with a cast operator. Casting is useful when a deliberate narrowing conversion is needed, but it can lose data if the target type is too small.

Key Points

  • Implicit is automatic
  • Explicit is programmer requested
  • Casting may lose data
Q1c2MUnit 1 — operators (arithmetic, relational, logical)
Core Concept

Differentiate Between Operator and Operands.

An operator is a symbol or keyword that tells the compiler to perform an operation such as addition, comparison or logical testing. An operand is a value or variable on which the operator acts. In the expression total plus one, total and one are operands while plus is the operator.

Key Points

  • Operator performs action
  • Operand receives action
  • Example with total plus one
Q1d2MUnit 1 — operators (arithmetic, relational, logical)
Core Concept

Define Conditional Operator with an example.

The conditional operator is a compact form of an if else statement. It takes three parts: a condition, a value for a true condition and a value for a false condition. For example, a mark of forty or more can print pass, otherwise it prints fail, using one expression.

Key Points

  • Three operands
  • True and false values
  • Compact if else form
Q1d2MUnit 1 — Input/output — scanf/printf in C
Core Concept

Write a C program to print all natural numbers from 10 to 100.

A simple loop starts from ten and continues while the counter is not greater than one hundred. Each pass prints the current value and then increases the counter by one. An integer counter is sufficient because all values are whole numbers. The loop stops after printing one hundred, so no extra value appears.

Key Points

  • Start at ten
  • Increment each pass
  • Stop after one hundred
Q1e2MUnit 2 — Loops — for
Core Concept

Find the Output of Code:

void main () { 
  int a, b; 
  for (a = 6, b = 4; a <= 24; a = a + 6) { 
    if (a % b == 0) break; 
  } 
  printf("%d", a); 
}

The loop starts with the first value at six and the divisor at four. Because six is not divisible by four, the body finishes and the value increases by six to twelve. At twelve the divisibility test succeeds and the break statement ends the loop. The printed value is twelve, not the later values that were never reached.

Key Points

  • Start at six
  • Divisible at twelve
  • Printed result is twelve
Q1e2MUnit 3 — Pointer — concept of address and pointer variable (concept only, not deep)
Core Concept

Define Pointer to Pointer.

A pointer to pointer stores the address of another pointer variable. It is useful when a function must change the pointer itself rather than the value it points to. In a linked list, a pointer to the head pointer allows insertion at the beginning without returning a new head from the function.

Key Points

  • Address of a pointer
  • Changes pointer itself
  • Useful for list head
Q1f2MUnit 1 — operators (arithmetic, relational, logical)
Core Concept

Find the output of following code: - #include<stdio.h> #define a 2*2+2 void main () { int b,c; b=2/a; c=b+4; printf("Value of variable b and c are %d%d respectively ", b,c); }

The macro replaces the name with its text before compilation, so missing parentheses change the calculation. Substituting the definition makes the division expand in an unexpected order, giving four for the first variable and eight for the second. The printed digits are therefore four and eight with no separating space.

Key Points

  • Macro text substitution
  • Precedence changes result
  • Printed output is digits four and eight
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

Write the importance of base value in recursive function.

A base value is the stopping condition of a recursive function. Without it, the function would keep calling itself and would eventually exhaust the call stack. The base case gives a direct answer for the smallest input, and every recursive call must move the problem closer to that case. This guarantees termination and a correct result.

Key Points

  • Stops recursion
  • Prevents stack exhaustion
  • Calls move toward base case
Q1g2MUnit 1 — Type conversion
Core Concept

Predict the output of following program:

#include<stdio.h> 
int main() { 
  int a = 12; 
  void *ptr = (int *)&a; 
  printf("%d", *ptr); 
  getchar(); 
  return 0; 
}

The address of the integer is stored in a general purpose pointer, then converted back to an integer pointer before reading. Dereferencing that pointer retrieves the original stored value. The program therefore prints twelve. The cast is needed because a general pointer cannot be dereferenced directly in standard C.

Key Points

  • General pointer holds address
  • Cast before dereference
  • Output is twelve
Q1g2MUnit 3 — 1D array — declaration
Core Concept

Draw block diagram to represent doubly linked list.

A doubly linked list node holds data and two links, one to the next node and one to the previous node. The first node has an empty previous link and the last has an empty next link. This structure allows movement in both directions and makes deletion easier when only a node pointer is known.

Key Points

  • Data plus two links
  • Previous and next
  • Moves both directions

Section B

7 Marks Each · 10 questions
Q2a7MUnit 1 — Data types
Survival ModePredicted

Explain the Storage Classes used for the storage of the Data in C programming.

Concept / Given Data The storage class specifier determines the lifetime, scope and linkage of a variable or function in C. Four primary classes exist: auto, register, static and extern. Each class influences where the compiler allocates memory (stack, data segment, or registers) and whether the identifier is visible across translation units.

Key Formula / Principle: StorageClass  ⇒  {Scope,  Lifetime,  Linkage}\text{StorageClass} \;\Rightarrow\; \{\text{Scope},\;\text{Lifetime},\;\text{Linkage}\}
  1. auto – Default for block‑level variables.
    • Scope: block (enclosed braces).
    • Lifetime: automatic; created on entry, destroyed on exit.
    • Linkage: none (unique to the block).
    • Typical use: temporary counters, loop indices.
  2. register – Hint to store the variable in a CPU register.
    • Scope: block, like auto.
    • Lifetime: automatic.
    • Linkage: none.
    • Restriction: cannot apply unary & (address cannot be taken).
  3. static – Two contexts:
    • Inside a function: retains value between calls; scope remains block.
    • Outside any function: gives internal linkage (visible only within the translation unit).
    • Lifetime: entire program execution.
    • Linkage: internal when file‑scope, none when block‑scope.
  4. extern – Declares a variable defined elsewhere.
    • Scope: file‑wide.
    • Lifetime: entire program.
    • Linkage: external, allowing access from other translation units.
    • Typical use: global variables shared across multiple source files.

Result: The four storage classes (auto, register, static, extern) together control where a variable lives, how long it persists, and whether other files can see it. Correctly choosing a class optimises memory usage and program modularity.

Tip from Examiner: Allocate 1 mark for each attribute (scope, lifetime, linkage). Common mistake – forgetting that `static` inside a function still has block scope but static lifetime.

Key Points

  • auto: block scope, automatic lifetime, no linkage
  • register: hint for CPU register, cannot take address
  • static: retains value across calls or internal linkage
  • extern: external linkage, defined in another file
Q2a7MUnit 2 — Control Statements
Core Concept

What is Flowchart what are the properties of Flowchart? Draw a flowchart to check number is a buzz number or not. (A number is said to be Buzz if it ends with 7 or divisible by 7).

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: What is Flowchart what are the properties of Flowchart? Draw a flowchart to check number is a buzz number or not. (A number is said to be Buzz if it ends with 7 or divisible by 7).

  • 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.

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.
Flowchart to test a buzz number read number n last digit seven yes no divisible by seven yes print buzzotherwise print not buzz
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.
Q2b7MUnit 1 — operators (arithmetic, relational, logical)
Survival ModePredictedRepeated

What is the importance of Precedence order and associativity? Explain Bitwise and Ternary operators in detail.

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
Q2b7MUnit 1 — Type conversion
Core Concept

Discuss the Concept of Type Casting and Type Conversion with the Program.

Concept / Given Data

Type casting in C is the explicit conversion of a value from one data type to another. It is written as a type name in parentheses before the expression, e.g., (int)3.7(int)3.7 or (float)5(float)5.

Key Formula / Principle

Explicit cast syntax: (type)  expression\text{(type)}\;\text{expression}

Step‑by‑Step Solution / Working

  1. Implicit conversion (promotion) occurs automatically when operands of different types are used in an expression. The smaller type is promoted to the larger type following the hierarchy: char→int→float→double\text{char} \rightarrow \text{int} \rightarrow \text{float} \rightarrow \text{double}.
  2. Explicit cast overrides this rule. The compiler first evaluates the expression, then converts the result to the specified type.
  3. Example program:
    #include <stdio.h>
    int main(){
        double d = 9.8;
        int i = (int)d;          // explicit cast
        float f = (float)5;      // cast integer to float
        printf("i=%d, f=%.1f\n", i, f);
        return 0;
    }
    
    Output: i=9, f=5.0.
  4. Conversion rules:
    • Integer to floating: value preserved.
    • Floating to integer: fractional part discarded (truncation).
    • Larger to smaller integer: possible loss of data.
    • Signed to unsigned: modulo arithmetic.
  5. Common pitfalls: forgetting parentheses in macro definitions, e.g., #define SQR(x) x*x leads to SQR(3+1) evaluating as 3+1*3+1 = 7 instead of 16.

Result: Explicit type casting gives the programmer control over conversions, ensuring correct data representation and preventing unintended truncation or overflow.

Tip from Examiner: For a 7‑mark answer, start with the definition, show the syntax, explain implicit vs explicit, give a concise program, and list conversion rules. Avoid long code; keep it under 30 lines.

Key Points

  • Explicit cast syntax: (type)expression
  • Implicit promotion hierarchy: char→int→float→double
  • Conversion rules: int→float preserves, float→int truncates
  • Macro pitfalls: missing parentheses cause wrong precedence
Q2c7MUnit 1 — operators (arithmetic, relational, logical)
Predicted

Write a program to print the pattern:




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: (i) Write a program in C language to print the following pattern: - 1 4 9 16 25 36 49 64 81 100 (ii) Write a program in C language to print the sum of following series: S = 1!/n! + 2!/n! + 3!/n! \dots x!/n!.

  • 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.
Q2c7MUnit 3 — 1D array — declaration
Core Concept

Write a program in C language to multiply 2 matrices of order n×nn \times n each and print the resultant matrix along with the transpose of the resultant 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 in C language to multiply 2 matrices of order n \times n each and print the resultant matrix along with the transpose of the resultant 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.
Q2d7MUnit 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

Write a Program to print the Fibonacci Series up to the user's choice with the process in which the function calls itself.

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 Program to print the Fibonacci Series up to the user's choice with the process in which the function calls itself.

  • 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.
Q2d7MUnit 3 — 1D array — declaration
Core Concept

Write a program in C language to implement Selection sort method.

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 in C language to implement Selection sort method.

  • 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.
Q2e7MUnit 1 — Data types
Predicted

Write the Short notes on (i) Linked list (ii) macros.

Concept / Given Data A linked list is a dynamic linear data structure where each node contains data and a pointer to the next node. It allows efficient insertion/deletion without shifting elements. A macro is a pre‑processor directive that performs textual substitution before compilation, enabling constant definitions and code snippets.

Key Formula / Principle: Node={data,  next  ∈  Node*}\text{Node}=\{\text{data},\;\text{next}\;\in\;\text{Node*}\}

Linked List – Short Note

  1. Structure:
    struct Node {
        int data;          // payload
        struct Node *next; // address of next node
    };
    
  2. Types: singly linked, doubly linked, circular.
  3. Operations:
    • Insertion at head: new->next=head;  head=new\text{new->next}=head;\;head=new.
    • Deletion at position k: traverse to (k−1)th(k-1)^{th} node, adjust pointers, free memory.
  4. Advantages: No contiguous memory requirement, O(1)O(1) insertion/deletion at known position.
  5. Disadvantages: Extra memory for pointers, O(n)O(n) search time, no random access.
  6. Use‑case in embedded systems: managing variable‑length buffers where memory is scarce.

Macros – Short Note

  1. Definition syntax: #define IDENTIFIER replacement‑list.
  2. Object‑like macro – constant substitution, e.g., #define MAX 100.
  3. Function‑like macro – parameterised, e.g., #define SQR(x) ((x)*(x)).
  4. Scope: file‑wide after the #define line; can be undefined with #undef.
  5. Advantages: Zero runtime overhead, easy to change constants, can create inline code snippets.
  6. Pitfalls:
    • Lack of type safety; arguments are not evaluated before substitution.
    • Need parentheses to avoid precedence errors, e.g., #define A 2*3 expands to 2*3 not (2*3).
    • Macro side‑effects: SQR(i++) increments i twice.
  7. Best practice: Prefer const or inline functions for type‑checked code; reserve macros for compile‑time constants and conditional compilation (#ifdef).

Result: Linked lists provide flexible, non‑contiguous storage with O(1)O(1) insert/delete, while macros offer compile‑time textual substitution but must be guarded with parentheses to avoid logical errors.

Tip from Examiner: Allocate 2 marks for definition, 2 marks for structure/usage, 1 mark for advantage, 1 mark for disadvantage, and 1 mark for a common macro‑trap example.

Key Points

  • Linked list: nodes with data + next pointer, dynamic memory
  • Macros: pre‑processor textual substitution, no runtime cost
  • Macro pitfalls: missing parentheses cause precedence errors
Q2e7MUnit 3 — File Handling Real connect: Arrays store sensor readings
Core Concept

Write a program to delete the end of the file using function feof(). Display the file pointer position for detecting end of 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 program to delete the end of the file using function feof(). Display the file pointer position for detecting end of 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.

Section C

7 Marks Each · 20 questions
Q3a7MUnit 1 — Data types
Predicted

What is the different user defined data types in C language? Write range, Format specifier, memory size of primitive data types.

Concept / Given Data:

C provides primitive (built-in) data types and allows the programmer to create user-defined data types by combining primitives. The question asks for both: (i) the user-defined types and (ii) a complete table of primitive types with range, format specifier, and memory size.

Key Principle: User-defined types are composite structures built from primitives; they do NOT introduce new storage — they only organise existing bytes.

Step 1 — User-Defined Data Types in C:

  1. struct — groups variables of different types under one name; each member gets its own memory. Size = sum of member sizes (plus padding for alignment).
  2. union — shares the same memory block among all members; only one member is valid at a time. Size = size of the largest member.
  3. enum — a set of named integer constants; stored as int (typically 44 bytes).

Step 2 — Primitive Data Types Table:

Data Type Memory Size Range Format Specifier
char 11 byte −128-128 to +127+127 (signed) / 00 to 255255 (unsigned) %c
int 22 or 44 bytes −32768-32768 to +32767+32767 (2-byte) / −231-2^{31} to 231−12^{31}-1 (4-byte) %d
float 44 bytes ±3.4×1038\pm 3.4 \times 10^{38}, ≈6\approx 6–77 significant digits %f
double 88 bytes ±1.7×10308\pm 1.7 \times 10^{308}, ≈15\approx 15 significant digits %lf
long 44 bytes −231-2^{31} to 231−12^{31}-1 %ld
unsigned int 22 or 44 bytes 00 to 6553565535 (2-byte) / 00 to 232−12^{32}-1 (4-byte) %u
void 00 bytes No value stored —

Step 3 — Explanation of Key Points:

  • char stores one ASCII character; signed char gives −128-128 to +127+127, while unsigned char gives 00 to 255255.
  • int size is compiler-dependent (ANSI C guarantees at least 22 bytes); on modern 6464-bit systems it is typically 44 bytes.
  • float uses IEEE-754 single precision: 11 sign bit + 88 exponent bits + 2323 mantissa bits.
  • double uses IEEE-754 double precision: 11 sign bit + 1111 exponent bits + 5252 mantissa bits.
  • void is used for functions returning nothing or for generic pointers (void *).

Result: C has exactly three user-defined data types (struct, union, enum) and six commonly used primitive types (char, int, float, double, long, unsigned int) plus void. Knowing the exact byte size and range is essential for memory allocation and overflow prevention in embedded systems.

Tip from Examiner: In 7-mark answers, always write the table with ALL four columns (type, size, range, specifier). Examiners deduct $1$–$2$ marks if the range column is missing. Also mention that `int` size is platform-dependent — writing a fixed value without qualification loses marks. For `struct` vs `union`, state the size formula explicitly: $\text{size(struct)} = \sum \text{member sizes}$ (with padding) vs $\text{size(union)} = \max(\text{member sizes})$.

Key Points

  • Three user-defined types: struct (sum of members), union (largest member), enum (named int constants)
  • char = 1 byte, range -128 to +127, format %c
  • int = 2 or 4 bytes (platform-dependent), format %d
  • float = 4 bytes, ~6-7 significant digits, format %f; double = 8 bytes, ~15 digits, format %lf
  • unsigned int doubles the positive range: 0 to 2^32 - 1 on 4-byte systems
  • void has 0 bytes, used for generic pointers and no-return functions
Q3a7MUnit 1 — Structure of a C program
Core Concept

Explain the Digital Computer with proper architecture.

Concept / Given Data:

A digital computer is an electronic device that processes data using binary logic (00 and 11). Its architecture follows the Von Neumann model, where both instructions and data reside in the same memory. The five major functional units are:

  1. Arithmetic Logic Unit (ALU) – performs arithmetic (++, −-, ×\times, ÷\div) and logical (AND\text{AND}, OR\text{OR}, NOT\text{NOT}) operations.
  2. Control Unit (CU) – fetches, decodes, and executes instructions; generates timing and control signals.
  3. Memory Unit – stores programs and data; divided into primary (RAM, ROM) and secondary (disk) storage.
  4. Input Unit – accepts data from external sources (keyboard, sensor).
  5. Output Unit – presents results (display, printer, actuator).
Key Principle – Von Neumann Cycle: Fetch→Decode→Execute→Store\text{Fetch} \rightarrow \text{Decode} \rightarrow \text{Execute} \rightarrow \text{Store}

Step-by-Step Working (Instruction Cycle):

  1. Fetch: The CU reads the instruction from memory address held in the Program Counter (PC) and places it in the Instruction Register (IR). The PC is incremented: PCnew=PCold+1PC_{new} = PC_{old} + 1.
  2. Decode: The CU interprets the opcode in IR and identifies operands and addressing mode.
  3. Execute: The ALU performs the required operation on operands fetched from registers or memory.
  4. Store: The result is written back to a register or memory location.
  5. Repeat: The cycle continues until a halt instruction is encountered.
Von Neumann ArchitectureControl Unit(CU)ALU(Arithmetic + Logic)Memory(RAM / ROM)(Instructions + Data)Input(Keyboard)Output(Display)System Bus: Data Bus + Address Bus + Control Bus

Bus System: All units communicate through three buses:

  • Data Bus – carries actual data (width = word size, e.g., 3232 or 6464 bits).
  • Address Bus – carries memory addresses (determines max addressable memory: 2n2^n where nn = number of address lines).
  • Control Bus – carries read/write, interrupt, and timing signals.

Result: The Von Neumann architecture enables sequential instruction execution with a shared memory, forming the basis of all modern processors (x86, ARM, RISC-V). C programs compiled for embedded microcontrollers (e.g., STM32, AVR) map directly onto this architecture — the compiler generates machine instructions that the CU fetches and the ALU executes.

Tip from Examiner: Always draw the diagram first (1 mark guaranteed). Label all five units + three buses. Mention the **stored-program concept** explicitly — it is the single most-asked differentiator. Common mistake: forgetting to mention that PC increments automatically after fetch. Unit trap: address bus width $n$ gives $2^n$ bytes of addressable space, not $n$ bytes.

Key Points

  • Von Neumann model: instructions and data share the same memory space
  • Five units: ALU, CU, Memory, Input, Output — connected via system bus
  • Instruction cycle: Fetch → Decode → Execute → Store; PC increments by 1 each cycle
  • Three buses: Data (word-size wide), Address (2^n addressable locations), Control (signals)
  • C programs compile to machine code that maps directly onto this architecture on microcontrollers
Q3b7MUnit 1 — Structure of a C program
Core Concept

Define Algorithm. Write the Algorithm for the greatest of three numbers and Draw its flow chart.

Concept / Definition:

An Algorithm is a finite, well-defined sequence of unambiguous steps that transforms given input into desired output within a bounded time. Every algorithm must satisfy five properties: finiteness (terminates), definiteness (each step is precise), input (zero or more), output (at least one), and effectiveness (each operation is basic enough to be performed).

Key Principle: To find the greatest of three numbers $a$, $b$, $c$, compare pairwise: $\max(a,b,c) = \max(\max(a,b),\, c)$.

Algorithm — Greatest of Three Numbers:

  1. START
  2. READ three numbers aa, bb, cc from input.
  3. IF a≥ba \geq b AND a≥ca \geq c THEN set max=a\text{max} = a GOTO step 7.
  4. ELSE IF b≥ab \geq a AND b≥cb \geq c THEN set max=b\text{max} = b GOTO step 7.
  5. ELSE set max=c\text{max} = c.
  6. (implicit fall-through)
  7. PRINT max\text{max} as the greatest number.
  8. STOP

Flowchart:

flowchart TD
    A([START]) --> B[/READ a, b, c/]
    B --> C{a >= b AND a >= c?}
    C -->|Yes| D[max = a]
    C -->|No| E{b >= a AND b >= c?}
    E -->|Yes| F[max = b]
    E -->|No| G[max = c]
    D --> H[/PRINT max/]
    F --> H
    G --> H
    H --> I([STOP])

Step-by-Step Trace (Example):

Let a=15a = 15, b=42b = 42, c=27c = 27.

  • Step 3: Check a≥ba \geq b? 15≥4215 \geq 42 → False. Skip.
  • Step 4: Check b≥ab \geq a? 42≥1542 \geq 15 → True. Check b≥cb \geq c? 42≥2742 \geq 27 → True. So max=42\text{max} = 42.
  • Step 7: Print 4242.

Result: The greatest of 1515, 4242, 2727 is 4242. The algorithm uses at most 4 comparisons in the worst case and exactly 2 in the best case (when aa is largest).

Tip from Examiner: In 7-mark algorithm questions, examiners award 1 mark for the definition, 3 marks for the step-by-step algorithm (numbered, with IF/ELSE clearly shown), and 3 marks for the flowchart. Common mistakes: forgetting the STOP terminal, using ambiguous words like "check if bigger" instead of precise relational expressions ($a \geq b$), and drawing a flowchart without decision diamonds (rhombus) for conditions. Always label both Yes/No branches on every diamond.

Key Points

  • Algorithm = finite, definite, effective sequence of steps with input and output
  • Greatest of three: compare a>=b AND a>=c, else b>=a AND b>=c, else c
  • Worst case 4 comparisons, best case 2 comparisons
  • Flowchart must use rhombus for decisions, parallelogram for I/O, rounded rectangle for start/stop
  • Always label Yes and No branches on every decision diamond
Q3b7MUnit 2 — Control Statements
Core Concept

How algorithm is different form flowchart. Write an algorithm to check number is a Prime number or not.

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: How algorithm is different form flowchart. Write an algorithm to check number is a Prime number or not.

  • 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.

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.
Prime number decision flow read number n n greater one test divisors factor found no means not primeno factor means prime
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.
Q4a7MUnit 1 — operators (arithmetic, relational, logical)
Survival ModePredictedRepeated

Illustrate the Concept of Operator Precedence and Associativity with 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
Q4a7MUnit 2 — Control Statements
Core Concept

Why break statement is required? Write a C program in C language to check character is a vowel or consonant.

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: Why break statement is required? Write a C program in C language to check character is a vowel or consonant.

  • 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 1 — operators (arithmetic, relational, logical)
Predicted

Write a program in C language to calculate energy bill. Read the starting and ending meter readings. The charges are as follows:- 0 < units <= 200: Rs 5.50 per Unit 200 < units <= 400: Rs 700 + Rs 6.0 per unit excess of 200 400 < units <= 600: Rs 1400 + Rs 7.50 per unit excess of 400 600 < units: Rs 1850 + Rs 9.0 per Unit excess of 600

Concept / Given Data

The problem requires a C program that reads two integer values: the starting meter reading SS and the ending meter reading EE. The number of units consumed is

units=E−S.\text{units}=E-S.

The tariff structure is piece‑wise:

Range of units Base charge Rate per excess unit
0<units≤2000<\text{units}\le200 00 5.505.50
200<units≤400200<\text{units}\le400 700700 6.06.0
400<units≤600400<\text{units}\le600 14001400 7.507.50
units>600\text{units}>600 18501850 9.09.0

The program must compute the total bill BB according to the applicable slab.

Key Formula / Principle: B={5.5×unitsif units≤200700+6.0×(units−200)if 200<units≤4001400+7.5×(units−400)if 400<units≤6001850+9.0×(units−600)if units>600B=\begin{cases}5.5\times\text{units}&\text{if }\text{units}\le200\\700+6.0\times(\text{units}-200)&\text{if }200<\text{units}\le400\\1400+7.5\times(\text{units}-400)&\text{if }400<\text{units}\le600\\1850+9.0\times(\text{units}-600)&\text{if }\text{units}>600\end{cases}

Step‑by‑Step Solution / Working

  1. Input – Use scanf("%d %d", &S, &E); to read the two readings.
  2. Compute units – int units = E - S; (assume E>SE>S).
  3. Determine slab – Use if‑else ladder:
    if (units <= 200) {
        bill = 5.5 * units;
    } else if (units <= 400) {
        bill = 700 + 6.0 * (units - 200);
    } else if (units <= 600) {
        bill = 1400 + 7.5 * (units - 400);
    } else {
        bill = 1850 + 9.0 * (units - 600);
    }
    
  4. Output – printf("Total bill: Rs %.2f\n", bill);.
  5. Edge cases – If units is zero or negative, print an error or set bill to zero.

Sample Run

Enter starting and ending readings: 1200 1500
Total bill: Rs 1650.00

Here, units = 300, which falls in the second slab: 700+6.0×(300−200)=700+600=1300700 + 6.0\times(300-200)=700+600=1300. The sample output shows a different value because the example uses arbitrary readings; the calculation logic remains the same.

Result: The program correctly calculates the energy bill for any valid meter readings by applying the appropriate tariff slab.

Tip from Examiner: Use `double` for `bill` to preserve fractional cents. Remember to handle the case where `E <= S` – either prompt again or set bill to zero. Mark the tariff table clearly in the answer sheet to show you understand the piece‑wise logic.

Key Points

  • Read two integers and compute units
  • Use if‑else ladder for piece‑wise tariff
  • Store bill in double for precision
  • Handle edge case E<=S
Q4b7MUnit 2 — Control Statements
Survival ModeRepeated

Write a Program to discuss the use of break in Switch Statement.

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 discuss the use of break in a switch case statement.

  • 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.
Q5a7MUnit 1 — operators (arithmetic, relational, logical)
Predicted

(i) Write a program in C language to print the following pattern: - 1 4 9 16 25 36 49 64 81 100 (ii) Write a program in C language to print the sum of following series: S=1!/n!+2!/n!+3!/n!…x!/n!S = 1!/n! + 2!/n! + 3!/n! \dots x!/n!.

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: (i) Write a program in C language to print the following pattern: - 1 4 9 16 25 36 49 64 81 100 (ii) Write a program in C language to print the sum of following series: S = 1!/n! + 2!/n! + 3!/n! \dots x!/n!.

  • 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.
Q5a7MUnit 2 — Control Statements
Core Concept

Write a Program to check whether the entered number is prime or not.

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 whether the entered number is prime or not.

  • 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.
Q5b7MUnit 1 — Data types
Predicted

Write a Program to print the multiplication of two-dimensional matrices with m×nm \times n dimensions.

Concept / Given Data A two‑dimensional matrix multiplication requires two matrices:

  • Matrix A of dimensions m×pm\times p (rows mm, columns pp)
  • Matrix B of dimensions p×np\times n (rows pp, columns nn) The resulting matrix C will have dimensions m×nm\times n.
Key Formula / Principle: Cij=∑k=1pAik BkjC_{ij}=\sum_{k=1}^{p}A_{ik}\,B_{kj}

Step‑by‑Step Solution / Working

  1. Read dimensions: Prompt user for mm, pp, and nn.
  2. Allocate arrays: Use 2‑D arrays int A[m][p], B[p][n], C[m][n]; (or dynamic allocation for large sizes).
  3. Input elements: Nested loops to fill A and B.
  4. Initialize result: Set all C[i][j] = 0 before accumulation.
  5. Compute product:
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < p; ++k) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    
    Each inner loop implements the summation in the formula.
  6. Display result: Nested loops to print C in matrix form.

Diagram

flowchart TD
    A[Matrix A (m×p)] -->|multiply| C[Matrix C (m×n)]
    B[Matrix B (p×n)] -->|multiply| C
    subgraph "Computation"
        A -->|for i| C
        B -->|for j| C
        C -->|for k| C
    end

Result: The program correctly prints the m×nm\times n product matrix CC where each element CijC_{ij} is the dot product of the ii‑th row of AA and the jj‑th column of BB. Verify by testing with small matrices (e.g., 2×32\times3 and 3×23\times2) and comparing with hand‑calculated values.

Tip from Examiner: Mark‑split: 1 mark for explaining dimensions, 1 for formula, 2 for code structure, 2 for loops, 1 for output. Common mistake: forgetting to initialize $C$ to zero, leading to garbage accumulation. Also, ensure the inner loop variable $k$ runs up to $p$, not $n$.

Key Points

  • Matrix multiplication requires matching inner dimensions pp
  • Result matrix dimensions are m×nm\times n
  • Use triple nested loops: i, j, k
  • Initialize result matrix to zero before accumulation
  • Verify with small test cases
Q5b7MUnit 3 — Structures
Core Concept

Write a program in C language using union to store name, mobile number, year of birth, fees deposited, total marks in class 12th and print only name and marks of class 12th of those students who have deposited fees less that 5000 and how born after year 2005.

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: Write a program in C language using union to store name, mobile number, year of birth, fees deposited, total marks in class 12th and print only name and marks of class 12th of those students who have deposited fees less that 5000 and how bo

  • 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.
Q6a7MUnit 3 — 1D array — declaration
Core Concept

Write a C program to find the presence of any particular element in an array of n number of elements using Binary search method.

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 C program to find the presence of any particular element in an array of n number of elements using Binary search method.

  • 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

  • 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 3 — 1D array — declaration
Core Concept

Write a Program to print the greatest number of an array using the array passing to function 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 — 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 print the greatest number of an array using the array passing to function 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.

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 — Control Statements
Core Concept

What are the different types of functions in C programming? Write a C program to print the multiplication of all the digits of a number using recursion.

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: What are the different types of functions in C programming? Write a C program to print the multiplication of all the digits of a number using recursion.

  • 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

  • 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.
Q6b7MUnit 3 — 1D array — declaration
Survival Mode

Define Sorting. Explain the Bubble sort technique and write the Program to implement the bubble sort.

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: Define Sorting. Explain the Bubble sort technique and write the Program to implement the bubble sort.

  • 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.
Q7a7MUnit 1 — File Handling
Core Concept

Define file. Write the modes of file handling. Write a program in C to write multiple lines to a text file.

Concept / Given Data A file is a persistent storage medium that allows a program to read from or write to a sequence of bytes. In C, file handling is performed through the standard I/O library (stdio.h) using a FILE * pointer. The file is opened with a mode that specifies the intended operation.

Key Formula / Principle

File opening syntax: FILE *fp = fopen(f¨ilename,¨ m¨ode)¨;\texttt{FILE *fp = fopen(\"filename\", \"mode\");}

Modes of file handling

  1. Read – "r" (open for reading; file must exist)
  2. Write – "w" (create/truncate; open for writing)
  3. Append – "a" (open for writing; writes appended to end)
  4. Read/Write – "r+" (open for update; reading and writing)
  5. Write/Read – "w+" (create/truncate; update)
  6. Append/Read – "a+" (open for update; writes appended)
  7. Binary – append "b" to any mode (e.g., "rb", "wb+")

Step‑by‑Step Solution / Working

  1. Include header: #include <stdio.h>.
  2. Declare a FILE *fp variable.
  3. Open the file in write mode: fp = fopen("output.txt", "w");.
  4. Check for NULL to handle errors.
  5. Write multiple lines using fprintf or fputs.
  6. Close the file with fclose(fp);.

Sample C program

#include <stdio.h>

int main(void) {
    FILE *fp = fopen("output.txt", "w");
    if (fp == NULL) {
        perror("Error opening file");
        return 1;
    }
    /* Write three lines */
    fprintf(fp, "Line 1: Hello, World!\n");
    fprintf(fp, "Line 2: C file handling demo.\n");
    fprintf(fp, "Line 3: End of file.\n");
    fclose(fp);
    return 0;
}

Result: The program creates output.txt containing the three lines. If the file already existed, it is truncated before writing.

Exam‑Tip Box

Tip from Examiner: Always check the return value of `fopen`. A `NULL` pointer indicates failure (e.g., permission denied). Use `perror` to print the system error message. Remember that `fprintf` automatically appends a newline if you include `\n`.

Key Points

  • A file is a persistent byte stream accessed via FILE *.
  • Modes: r, w, a, r+, w+, a+, with optional b for binary.
  • fopen returns NULL on failure; handle it with perror.
  • Use fprintf/fputs to write; close with fclose.
  • Binary mode (b) is required on Windows for non‑text files.

Key Points

  • A file is a persistent byte stream accessed via FILE *
  • Modes: r, w, a, r+, w+, a+, with optional b for binary
  • fopen returns NULL on failure; check and use perror
  • Use fprintf/fputs to write; close with fclose
  • Binary mode is required on Windows for non‑text files
Q7a7MUnit 3 — Pointer — concept of address and pointer variable (concept only, not deep)
Core Concept

What are the advantages of Dynamic memory allocation over static memory allocation? Write a program to display two numbers with malloc () and reallocate memory for displaying three 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 — 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: What are the advantages of Dynamic memory allocation over static memory allocation? Write a program to display two numbers with malloc () and reallocate memory for displaying three numbers.

  • 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.
Q7b7MUnit 1 — File Handling
Core Concept

Define calloc function. Write the Program to print the sum of elements initialized at the dynamic memory allocated by the user.

Concept / Given Data

The calloc function is a standard library routine used for dynamic memory allocation. It allocates a contiguous block of memory for an array of elements, initializes all bytes to zero, and returns a pointer to the first byte of the block. The prototype is:

void *calloc(size_t nmemb, size_t size);
  • nmemb – number of elements to allocate.
  • size – size of each element in bytes.

When the user supplies the number of elements, calloc ensures that the memory is zero‑initialized, which is useful for avoiding garbage values.

Key Formula / Principle

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

$$
\text{ptr} = \text{calloc}(n, \text{sizeof}(\text{type}))
$$

</div>

Step‑by‑Step Solution / Working

  1. Include headers – #include <stdio.h> and #include <stdlib.h>.
  2. Read number of elements – int n; printf("Enter number of elements: "); scanf("%d", &n);.
  3. Allocate memory – int *arr = (int *)calloc(n, sizeof(int));.
    • If arr == NULL, handle allocation failure.
  4. Populate array – Use a loop to read each element: for (int i = 0; i < n; ++i) { printf("Enter element %d: ", i+1); scanf("%d", &arr[i]); }.
  5. Compute sum – Initialize int sum = 0; and accumulate: for (int i = 0; i < n; ++i) sum += arr[i];.
  6. Print result – printf("Sum of elements = %d\n", sum);.
  7. Free memory – free(arr); to avoid leaks.

Example Program

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int n, sum = 0;
    printf("Enter number of elements: ");
    scanf("%d", &n);

    int *arr = (int *)calloc(n, sizeof(int));
    if (!arr) {
        fprintf(stderr, "Memory allocation failed\n");
        return 1;
    }

    for (int i = 0; i < n; ++i) {
        printf("Enter element %d: ", i + 1);
        scanf("%d", &arr[i]);
        sum += arr[i];
    }

    printf("Sum of elements = %d\n", sum);
    free(arr);
    return 0;
}

Result: The program prints the sum of all user‑entered integers stored in dynamically allocated memory. The use of calloc guarantees that any uninitialized elements (if the user skips input) start at zero, preventing accidental inclusion of garbage values in the sum.

Tip from Examiner: Remember to check the return value of *calloc* for `NULL`. Also, always `free()` the memory after use to avoid leaks. For a 7‑mark answer, include the prototype, key formula, step‑by‑step logic, and a complete code snippet.

Key Points

  • calloc allocates zero‑initialized memory
  • Prototype: void *calloc(size_t nmemb, size_t size)
  • Use sizeof(type) for element size
  • Always check for NULL and free memory
Q7b7MUnit 3 — File Handling Real connect: Arrays store sensor readings
Core Concept

Define any 3 functions which are used for file handling in C language. Write a program in C language to count total number vowels in a text 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: Define any 3 functions which are used for file handling in C language. Write a program in C language to count total number vowels in a text 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.