NBC 103 • Unit 110 min readHigh Exam Frequency

C Program Structure, Tokens, Data Types & Operators

Unit 1: Algorithms, Flowcharts & C Program ArchitectureProblem Solving Using C

👨‍🏫 Professor's Mental Model: The Recipe & Kitchen Ingredients

C Program ek Master Recipe ki tarah hai. Variables wo dabbe hain jinme ingredients (data jaise int, float) rakhte hain. Operators churi aur gas burner hain jo ingredients par action karte hain. Aur compiler kitchen inspector hai jo dekhta hai ki recipe me koi grammatical galti toh nahi hai!

Anatomy of a C Program & Compilation Pipeline

A C program follows a standard modular structure: Preprocessor Directives (#include), Global Declarations, main() function entry point, and User-Defined Functions. Compilation Flow: Source Code (.c) -> Preprocessor (#include expansion) -> Expanded Code (.i) -> Compiler (Syntax/Semantic Analysis) -> Assembly Code (.s) -> Assembler -> Object Code (.obj/.o) -> Linker (combines runtime libraries) -> Executable (.exe).
Syntax / Calculation Rule:
#include <stdio.h>

int main(void) {
    printf("Hello, BCA Scholar!\n");
    return 0;
}

C Tokens: Keywords, Identifiers & Data Types

Tokens are the smallest building blocks in C: 1. Keywords: 32 reserved words (auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while). 2. Identifiers: Variable/Function names (must begin with letter or underscore, no spaces, case-sensitive). 3. Data Types: char (1B, %c), int (4B, %d), float (4B, %f), double (8B, %lf), void.

Operators, Precedence & Associativity

Arithmetic (+, -, *, /, %), Relational (==, !=, <, >, <=, >=), Logical (&&, ||, !), Bitwise (&, |, ^, ~, <<, >>), Increment/Decrement (++a, a--), Conditional Ternary ((a > b) ? a : b), sizeof operator.

Interactive Tested Code Example

#include <stdio.h>

int main(void) {
    int a = 15, b = 4;
    printf("Arithmetic Operations on %d and %d:\n", a, b);
    printf("Addition:       %d + %d = %d\n", a, b, a + b);
    printf("Division:       %d / %d = %d\n", a, b, a / b);
    printf("Modulus (Rem):  %d %% %d = %d\n", a, b, a % b);
    printf("Ternary Max:    Largest is %d\n", (a > b) ? a : b);
    return 0;
}
💡 Note:Demonstrates integer division (truncates fraction) vs modulus operator (%) which computes remainder, and conditional ternary operator.

🎯 University Exam Scoring Blueprint

  • Modulus operator (%) works ONLY with integers, never floats.
  • State that 32 keywords exist in ANSI C.
  • Explain the difference between pre-increment (++x: increment then use) and post-increment (x++: use then increment).

Top Viva Questions on C Program Structure, Tokens, Data Types & Operators

1 Questions
1

What is the difference between = and == in C?