If you are a 1st year B.Tech student studying under Maulana Abul Kalam Azad University of Technology (MAKAUT), Unit 1 of Programming for Problem Solving (PPS-II / BS-CS201 / ES-CS201) forms the fundamental bedrock of your engineering degree. Whether you are aiming to ace your CA1 / CA2 class tests, maximize your End-Semester Online CA (ECA) score, or target an O-grade (90+) in the 70-mark End-Semester theory examination, mastering C operators and decision control structures is essential.
In this guide, we break down the entire MAKAUT Unit 1 syllabus into actionable concepts, memory layouts, operator precedence rules, and fully tested code examples straight from university past paper trends.
This guide is strictly aligned with the updated MAKAUT credit curriculum regulations. All code snippets are verified against GCC (C99/C11 standards) commonly used in college labs across West Bengal.
---
1. The C Compilation Pipeline Explained
In MAKAUT semester viva-voce and Group A short questions (2 Marks), examiners frequently ask: *"What happens under the hood when a C program compiles?"*
When you write a program main.c and compile it via GCC (gcc main.c -o main), the code passes through 4 distinct phases:
1+-------------------+ +-------------------+ +-------------------+ +------------------+2| Source Code | --> | Expanded Source | --> | Assembly Code | --> | Object Code | --> Executable3| main.c | | main.i | | main.s | | main.o | main.exe4+-------------------+ +-------------------+ +-------------------+ +------------------+5 [Preprocessor] [Compiler Engine] [Assembler] [Linker]
The 4 Stages:
- Preprocessing (`.c` to `.i`):
- Expands macros (
#define). - Replaces header includes (
#include <stdio.h>) with actual header declarations. - Strips all comments (
//and/* ... */). - Compilation (`.i` to `.s`):
- Translates expanded C code into target assembly language (
.s). - Performs syntax checking, type validation, and register allocation optimization.
- Assembly (`.s` to `.o` / `.obj`):
- Converts assembly mnemonic instructions into binary machine code object files.
- Linking (`.o` to Binary Executable):
- Links your object code with external standard library binaries (e.g.,
printfimplementation fromlibc). - Resolves symbol addresses to produce the final executable binary.
To inspect intermediate preprocessor output in GCC for debugging, run: gcc -E main.c -o main.i.
---
2. Data Types, Storage Sizes & Format Specifiers
C is a statically typed language. Every variable must have an explicit data type that dictates how many bytes are allocated in RAM and how bits are interpreted.
| Data Type | Keyword | Size (32/64-bit GCC) | Numeric Range | Format Specifier |
|---|---|---|---|---|
| Character | char | 1 Byte (8 bits) | -128 to 127 | %c |
| Unsigned Char | unsigned char | 1 Byte | 0 to 255 | %c |
| Integer | int | 4 Bytes (32 bits) | -2,147,483,648 to 2,147,483,647 | %d or %i |
| Short Int | short | 2 Bytes (16 bits) | -32,768 to 32,767 | %hd |
| Float | float | 4 Bytes | 1.2 × 10^{-38} to 3.4 × 10^{38} (6 decimal places) | %f |
| Double | double | 8 Bytes | 2.3 × 10^{-308} to 1.7 × 10^{308} (15 decimal places) | %lf |
| Pointer | void* | 4 Bytes (32-bit) / 8 Bytes (64-bit) | Hexadecimal RAM Address | %p |
---
3. C Operators & Precedence Master Table
In MAKAUT Group A questions, expression evaluation problems (e.g., res = 5 + 3 * 2 % 4 / 2) carry guaranteed 2 marks. To solve them without mistakes, you must memorize operator priority and associativity direction.
Complete Operator Precedence Table
| Priority | Category | Operators | Associativity | ||
|---|---|---|---|---|---|
| 1 (Highest) | Postfix | () [] -> . ++ (post) -- (post) | Left to Right | ||
| 2 | Unary | + - ! ~ ++ (pre) -- (pre) (type) * & sizeof | Right to Left | ||
| 3 | Multiplicative | * / % | Left to Right | ||
| 4 | Additive | + - | Left to Right | ||
| 5 | Bitwise Shift | << >> | Left to Right | ||
| 6 | Relational | < <= > >= | Left to Right | ||
| 7 | Equality | == != | Left to Right | ||
| 8 | Bitwise AND | & | Left to Right | ||
| 9 | Bitwise XOR | ^ | Left to Right | ||
| 10 | Bitwise OR | ` | ` | Left to Right | |
| 11 | Logical AND | && | Left to Right | ||
| 12 | Logical OR | ` | ` | Left to Right | |
| 13 | Ternary | ?: | Right to Left | ||
| 14 | Assignment | = += -= *= /= %= &= ^= ` | = <<= >>=` | Right to Left | |
| 15 (Lowest) | Comma | , | Left to Right |
Modulus % works strictly on integer types in standard C. Expressions like 7.5 % 2.0 cause a compilation error. For floating-point remainder calculations, use fmod(7.5, 2.0) from <math.h>.
---
4. Decision Making Control Structures
Decision control statements dictate which code branch executes depending on boolean evaluations (1 for true, 0 for false).
1. The if-else Ladder
Evaluates conditions sequentially from top to bottom. Once a condition succeeds, its block executes and the remaining ladder is skipped.
2. The Dangling else Problem
When nested if statements lack explicit curly braces { }, an else automatically binds to the closest un-matched preceding `if`.
1// Dangerous ambiguous code:2if (score > 50)3 if (attendance > 75)4 printf("Eligible");5else6 printf("Not Eligible"); // BUG! Belongs to (attendance > 75), NOT (score > 50)!78// Fixed cleanly with curly braces:9if (score > 50) {10 if (attendance > 75) {11 printf("Eligible");12 }13} else {14 printf("Not Eligible");15}
---
5. The switch-case Statement Rules
A switch statement provides multi-way branching based on integral equality matching.
Mandatory Rules for MAKAUT Exams:
- Integral Expression Only: The condition inside
switch(expr)must evaluate toint,char, orenum.floatordoubleare invalid. - Constant Case Labels:
case 10:orcase 'A':are valid. Variable labels likecase x:cause compile errors. - Fallthrough Behavior: Omitting
break;causes execution to fall through into all lower case blocks regardless of condition match.
---
6. Solved MAKAUT Exam Programs
Here are core Unit 1 programs frequently asked in MAKAUT semester papers (Programs 1 to 41 from unit_1_basics_operators_control_flow).
Program 1: Swapping 2 Variables (Without 3rd Variable)
*Exam Context: Group B (5 Marks)*
1"text-[#cf222e] dark:text-[#c586c0] font-semibold">#include "text-[#0a3069] dark:text-[#ce9178]"><stdio.h>23int main() {4 int a, b;5 printf("Enter two integers(a and b): ");6 if (scanf("%d %d", &a, &b) != 2) {7 printf("Invalid input!\n");8 return 1;9 }1011 printf("Before Swapping: a = %d, b = %d\n", a, b);1213 // Arithmetic swapping algorithm without temporary variable14 a = a + b;15 b = a - b;16 a = a - b;1718 printf("After Swapping: a = %d, b = %d\n", a, b);19 return 0;20}
---
Program 2: Leap Year Verification with Nested Logic
*Exam Context: Group B (5 Marks)*
1"text-[#cf222e] dark:text-[#c586c0] font-semibold">#include "text-[#0a3069] dark:text-[#ce9178]"><stdio.h>23int main() {4 int year;5 printf("Enter year: ");6 scanf("%d", &year);78 // A year is a leap year if divisible by 4 AND not 100, OR divisible by 4009 if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {10 printf("%d is a Leap Year.\n", year);11 } else {12 printf("%d is NOT a Leap Year.\n", year);13 }1415 return 0;16}
---
Program 3: Roots of a Quadratic Equation (ax^2 + bx + c = 0)
*Exam Context: Group C (15 Marks)*
1"text-[#cf222e] dark:text-[#c586c0] font-semibold">#include "text-[#0a3069] dark:text-[#ce9178]"><stdio.h>2"text-[#cf222e] dark:text-[#c586c0] font-semibold">#include "text-[#0a3069] dark:text-[#ce9178]"><math.h>34int main() {5 double a, b, c, disc, r1, r2, realPart, imagPart;67 printf("Enter coefficients a, b and c: ");8 scanf("%lf %lf %lf", &a, &b, &c);910 if (a == 0) {11 printf("Coefficient 'a' cannot be 0 for a quadratic equation.\n");12 return 1;13 }1415 disc = b * b - 4 * a * c;1617 if (disc > 0) {18 r1 = (-b + sqrt(disc)) / (2 * a);19 r2 = (-b - sqrt(disc)) / (2 * a);20 printf("Roots are Real & Distinct: Root 1 = %.2lf, Root 2 = %.2lf\n", r1, r2);21 } else if (disc == 0) {22 r1 = r2 = -b / (2 * a);23 printf("Roots are Real & Equal: Root 1 = Root 2 = %.2lf\n", r1);24 } else {25 realPart = -b / (2 * a);26 imagPart = sqrt(-disc) / (2 * a);27 printf("Roots are Complex & Imaginary:\n");28 printf("Root 1 = %.2lf + %.2lfi\n", realPart, imagPart);29 printf("Root 2 = %.2lf - %.2lfi\n", realPart, imagPart);30 }3132 return 0;33}
---
Program 4: Official MAKAUT Grading System Implementation
*Exam Context: Group B (5 Marks)*
1"text-[#cf222e] dark:text-[#c586c0] font-semibold">#include "text-[#0a3069] dark:text-[#ce9178]"><stdio.h>23int main() {4 float marks;5 printf("Enter student marks(0-100): ");6 scanf("%f", &marks);78 if (marks < 0 || marks > 100) {9 printf("Invalid marks input!\n");10 } else if (marks >= 90) {11 printf("MAKAUT Grade: O(Outstanding) | Credit Point: 10\n");12 } else if (marks >= 80) {13 printf("MAKAUT Grade: E(Excellent) | Credit Point: 9\n");14 } else if (marks >= 70) {15 printf("MAKAUT Grade: A(Very Good) | Credit Point: 8\n");16 } else if (marks >= 60) {17 printf("MAKAUT Grade: B(Good) | Credit Point: 7\n");18 } else if (marks >= 50) {19 printf("MAKAUT Grade: C(Fair) | Credit Point: 6\n");20 } else if (marks >= 40) {21 printf("MAKAUT Grade: D(Below Avg) | Credit Point: 5\n");22 } else {23 printf("MAKAUT Grade: F(Fail) | Credit Point: 0\n");24 }2526 return 0;27}
---
Program 5: Electricity Bill Generator (Slab Based)
*Exam Context: Group B / Group C (10 Marks)*
1"text-[#cf222e] dark:text-[#c586c0] font-semibold">#include "text-[#0a3069] dark:text-[#ce9178]"><stdio.h>23int main() {4 float units, bill = 0.0, totalBill;56 printf("Enter total units consumed: ");7 scanf("%f", &units);89 if (units <= 100) {10 bill = units * 3.50;11 } else if (units <= 200) {12 bill = (100 * 3.50) + ((units - 100) * 4.50);13 } else if (units <= 300) {14 bill = (100 * 3.50) + (100 * 4.50) + ((units - 200) * 5.50);15 } else {16 bill = (100 * 3.50) + (100 * 4.50) + (100 * 5.50) + ((units - 300) * 6.50);17 }1819 // Add 10% surcharge if base bill exceeds Rs. 100020 if (bill > 1000) {21 totalBill = bill + (bill * 0.10);22 } else {23 totalBill = bill;24 }2526 printf("Base Energy Charge : Rs. %.2f\n", bill);27 printf("Total Bill Amount : Rs. %.2f\n", totalBill);28 return 0;29}
---
7. Exam Day Checklist for Unit 1
- Always verify header files (
<stdio.h>,<math.h>). When using<math.h>in Linux/GCC labs, compile with-lmflag:gcc program.c -lm. - Draw clean flowcharts for quadratic equations and switch statements in Group C questions.
- Clearly mention format specifiers (
%d,%f,%lf,%c) when writing code answers on exam answer sheets.