Unit 2: Constant and Variable

Contents

1. Programming Language Levels

Programming languages are categorized based on their proximity to computer hardware.

2. C Program Structure

Every C program follows a standard template to ensure the compiler can process the code correctly.

/* Documentation Section: Description of program */
#include <stdio.h>  // Link Section: Preprocessor directives

// Global Declaration Section (Optional)

int main()          // Main Function Section
{
    // Declaration part
    // Execution part
    
    return 0;
}
    

3. Character Set & Tokens

The Character Set includes all characters that the C compiler recognizes.

4. Identifiers and Keywords

Keywords

Keywords are reserved words that have a predefined meaning to the C compiler. They cannot be used as names for variables.

Rule: There are 32 standard keywords in C (e.g., int, float, if, else, while, return).

Identifiers

Identifiers are user-defined names given to various program elements like variables, functions, and arrays.

5. Constants and Variables

Variables

A variable is a data name used to store a data value that can change during program execution.

Example: int age = 20; (Here, 'age' is a variable).

Constants

A constant is a value that does not change during the program execution.

Constant Type Examples
Integer Constants 10, -50, 1000
Real (Floating-point) 3.14, -0.005, 1.5
Character Constants 'A', 'z', '5'
String Constants "Hello", "Knowlet", "123"

6. Exam Focus Enhancements

Exam Tips
Common Mistakes
Frequently Asked Questions

Q: What is the difference between an identifier and a keyword?
A: A keyword is a reserved word with a fixed meaning; an identifier is a name created by the programmer for variables or functions.

Q: Why is C called a Middle-Level language?
A: Because it combines the features of low-level languages (direct memory access) with the ease of high-level languages.