NBC 103 • Unit 115 min readHigh Exam Frequency

C Tokens, Keywords, Identifiers & Primitive Data Types

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

👨‍🏫 Professor's Mental Model: The Alphabet, Grammar Rules & Sized Storage Containers

Jaise English bhasha me words, punctuation marks aur grammar hoti hai, waise hi C language ki sabse choti units ko Tokens kehte hain. Keywords dictionary ke wo 32 reserved shabd hain jinka matlab badla nahi ja sakta. Identifiers aapke banaye hue naam hain (jaise variable ya function ka naam). Aur Data Types alag-alag aakaar ke plastic dabbe hain: char 1-byte ka chota dabba hai, int 4-byte ka dabba hai, aur double 8-byte ka bada container hai!

Academic Lecture Notes & Solved Study Pages

Unit 1 • Core Concepts, Step-by-Step Proofs & Notebook Solutions

3 Notebook Pages
NOTEBOOK PAGE 1 OF 3

1. The 6 Categories of C Tokens

A Token is the smallest individual unit in a C program recognized by the compiler's lexical analyzer. The 6 token types are:

Keywords: 32 reserved system words (e.g., int, return, if, while).
Identifiers: Names given to variables, functions, arrays, and user tags (e.g., total_marks, calculate_area).
Constants: Fixed invariant values (e.g., 42, 3.14159, 'A', "Hello").
Strings: Character sequences enclosed in double quotes (e.g., "DevBCA").
Special Symbols: Brackets, commas, semicolons (e.g., [], {}, (), ;, ,).
Operators: Mathematical and logical action symbols (e.g., +, -, *, &&, ||).
NOTEBOOK PAGE 2 OF 3

2. The 32 ANSI C Keywords & Identifier Naming Conventions

The 32 reserved keywords in standard ANSI C: 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.

Mandatory Rules for Constructing Valid Identifiers:

Can contain letters (A-Z, a-z), digits (0-9), and the underscore character (_).
Must strictly begin with a letter or underscore (NEVER a digit: 1st_rank is ILLEGAL; rank_1 is LEGAL).
Case-Sensitive: Total, total, and TOTAL refer to 3 completely different memory variables.
No white spaces or special symbols allowed (total-marks or total marks are ILLEGAL).
A keyword cannot be used as an identifier name (int while = 5; is a SYNTAX ERROR).
NOTEBOOK PAGE 3 OF 3

3. Primitive Data Types, Memory Sizes & Ranges (32-bit/64-bit Architecture)

Fundamental data types allocate contiguous byte blocks in RAM:

char (1 Byte / 8 bits):
- signed char: -128 to +127 (%c, %d)
- unsigned char: 0 to 255 (%c, %u)
int (4 Bytes / 32 bits on modern systems; 2 Bytes on 16-bit Turbo C):
- signed int: -2,147,483,648 to +2,147,483,647 (%d)
- unsigned int: 0 to 4,294,967,295 (%u)
- short int: 2 Bytes, -32,768 to +32,767 (%hd)
- long long int: 8 Bytes, -9*10^18 to +9*10^18 (%lld)
float (4 Bytes / 32 bits IEEE 754):
- Single precision, ~6 decimal digits precision (%f)
double (8 Bytes / 64 bits IEEE 754):
- Double precision, ~15-17 decimal digits precision (%lf)
void (0 Bytes): Represents valueless return or empty parameter lists.
Master C Primitive Data Types Specification Matrix
Data TypeType ModifierSize (Bytes)BitsFormat SpecifierTypical Value Range
charsigned18%c / %d-128 to 127
charunsigned18%c / %u0 to 255
intsigned short216%hd-32,768 to 32,767
intunsigned short216%hu0 to 65,535
intsigned int432%d-2,147,483,648 to 2,147,483,647
intunsigned int432%u0 to 4,294,967,295
intsigned long long864%lld-9.22 × 10^18 to +9.22 × 10^18
floatstandard432%f±1.2 × 10^-38 to ±3.4 × 10^38 (6 prec)
doublestandard864%lf±2.3 × 10^-308 to ±1.7 × 10^308 (15 prec)
long doubleextended12 or 1696/128%Lf±3.4 × 10^-4932 to ±1.1 × 10^4932 (19 prec)

Interactive Tested Code Example

#include <stdio.h>
#include <limits.h>
#include <float.h>

int main(void) {
    printf("=== C DATA TYPE MEMORY ARCHITECTURE ===\n\n");
    printf("char:        %zu Byte  | Min: %d to Max: %d\n", sizeof(char), CHAR_MIN, CHAR_MAX);
    printf("short int:   %zu Bytes | Min: %d to Max: %d\n", sizeof(short), SHRT_MIN, SHRT_MAX);
    printf("int:         %zu Bytes | Min: %d to Max: %d\n", sizeof(int), INT_MIN, INT_MAX);
    printf("long long:   %zu Bytes | Min: %lld to Max: %lld\n", sizeof(long long), LLONG_MIN, LLONG_MAX);
    printf("float:       %zu Bytes | Precision: %d digits\n", sizeof(float), FLT_DIG);
    printf("double:      %zu Bytes | Precision: %d digits\n", sizeof(double), DBL_DIG);
    return 0;
}
💡 Note:Uses sizeof operator alongside standard C headers <limits.h> and <float.h> to dynamically query machine word size and boundary limits.

🎯 University Exam Scoring Blueprint

  • In university exams, explicitly state that sizeof(char) is defined by the ANSI C standard as strictly 1 byte.
  • Point out that int can be 2 bytes on 16-bit microcontrollers/Turbo C or 4 bytes on modern 32/64-bit GCC compilers.
  • Identify valid and invalid identifier examples: _score (Valid), $amount (Invalid), 3rd_term (Invalid), student_age (Valid).

Top Viva Questions on C Tokens, Keywords, Identifiers & Primitive Data Types

2 Questions
1

What happens when an unsigned char exceeds its maximum value of 255?

2

Can an identifier in C begin with an underscore (_)?