Paramclasses Academy - Blog

Tutorials Details

←
Post 3 of 15
→

What is C Tokens, Keywords and Identifiers in C programming

What is C Tokens, Keywords and Identifiers in C programming

October 13, 2026

1. Introduction

Every C program consists of small individual elements that form instructions. These elements are called tokens.

Understanding tokens, keywords, and identifiers is essential for learning C syntax and writing correct programs.

Consider this program:

#include <stdio.h>

int main(void) {
    int age = 20;
    printf("Age: %d\n", age);
    return 0;
}

This program contains several types of tokens, including keywords (int, return), identifiers (main, age, printf), operators (=), constants (20), and punctuation symbols such as braces and semicolons.

Learning objectives

By the end of this module, you will be able to:

  • Understand tokens in C programming.

  • Identify the different types of tokens.

  • Recognize C keywords and their purpose.

  • Create valid identifiers for variables and functions.

  • Understand constants, operators, and special symbols.

  • Identify common syntax mistakes in C programs.

2. What Are Tokens in C?

A token is a basic lexical unit of a C program recognized by the compiler during lexical analysis.

C tokens are commonly grouped into six categories:

1. Keywords

Reserved words with defined meanings, such as int and return.

2. Identifiers

Names of variables, functions, and other program entities, such as age and main.

3. Constants

Fixed literal values, such as 10, 3.14, and 'A'.

4. String literals

Text enclosed in double quotes, such as "Hello World".

5. Operators

Symbols that perform operations, such as +, -, =, and *.

6. Punctuators (special symbols)

Symbols that structure the program, such as ;, (), {}, and ,.

3. Example: Identifying Tokens

Consider the statement:

int total = price + 50;

Its tokens are:

Token

Category

int

Keyword

total

Identifier

=

Operator

price

Identifier

+

Operator

50

Integer constant

;

Punctuator

Spaces help separate tokens in this example, but C does not require spaces around every operator. For example, total=price+50; contains the same basic tokens.

4. What Are Keywords in C?

Keywords are reserved words that have predefined meanings in the C language. They cannot be used as ordinary identifiers.

Examples include:

int
char
float
if
else
for
while
return
void
static
struct

For example:

int marks = 90;

Here, int tells the compiler that marks has the type int.

Traditional 32 C keywords

The following table lists the 32 keywords from the original C89/C90 standard. Modern C standards introduce additional keywords.

Keyword

Purpose

auto

Declares automatic storage duration in applicable declarations.

break

Exits a loop or switch.

case

Labels a switch branch.

char

Character type.

const

Qualifies an object or type as nonmodifiable through that qualified type.

continue

Moves to the next loop iteration.

default

Default branch in a switch.

do

Begins a do-while loop.

double

Double-precision floating-point type.

else

Alternative branch of an if statement.

enum

Defines an enumeration type.

extern

Declares an identifier with external linkage in common uses.

float

Floating-point type.

for

Begins a for loop.

goto

Transfers control to a labeled statement.

if

Conditional statement.

int

Integer type.

long

Type modifier.

register

Storage-class specifier that may suggest register storage.

return

Returns control from a function.

short

Type modifier.

signed

Signed integer type modifier.

sizeof

Determines the size in bytes of a type or object expression.

static

Specifies static storage duration or internal linkage, depending on context.

struct

Defines a structure type.

switch

Multiway selection statement.

typedef

Creates a type alias.

union

Defines a union type.

unsigned

Unsigned integer type modifier.

void

Indicates no value or an unspecified type, depending on context.

volatile

Type qualifier for objects that may change in ways not captured by ordinary program flow.

while

Begins a while loop.

Note: C99, C11, C17, and C23 add or introduce further keywords and keyword spellings. The list above is the traditional 32-keyword list, not a complete list for every modern C standard.

5. Can Keywords Be Used as Variable Names?

No. A keyword cannot be used as an ordinary variable or function identifier.

Invalid examples:

int return = 10;
int while = 5;
int if = 20;

These declarations produce syntax errors because return, while, and if are keywords.

Correct alternatives:

int return_value = 10;
int loop_count = 5;
int condition_result = 20;

Choose descriptive names that explain the purpose of the data.

6. What Are Identifiers in C?

An identifier is a name used to identify a program entity, such as a variable, function, structure, or typedef name.

Example:

int student_age = 18;
float account_balance = 2500.50f;

void display_message(void) {
    printf("Welcome!\n");
}

In this example:

  • student_age is an identifier.

  • account_balance is an identifier.

  • display_message is an identifier.

  • printf is also an identifier provided by the standard library.

Rules for naming identifiers

  1. An identifier can contain letters, digits, and underscores.

  2. It cannot begin with a digit.

  3. It cannot contain spaces.

  4. It cannot be a keyword.

  5. C identifiers are case-sensitive.

  6. Avoid identifiers that begin with underscores in many contexts, because some such names are reserved to the implementation.

  7. Choose meaningful names for readability.

Valid identifiers

age
student_name
totalMarks
marks2
_count

Invalid identifiers

2marks       // Starts with a digit
student name // Contains a space
float        // Keyword
total-marks  // Contains a hyphen

7. C Is Case-Sensitive

C distinguishes uppercase and lowercase letters.

int age = 20;
int Age = 25;
int AGE = 30;

These are three different identifiers.

Example:

#include <stdio.h>

int main(void) {
    int score = 90;
    int Score = 75;

    printf("%d\n", score);
    printf("%d\n", Score);

    return 0;
}

Output:

90
75

Using different capitalization for related variables can cause confusion, so use a consistent naming style.

8. Constants and String Literals

Constants and string literals are also tokens.

Integer and floating-point constants

int age = 21;
float price = 99.50f;
double pi = 3.14159;

Examples of constants are 21, 99.50f, and 3.14159.

Character constants

char grade = 'A';
char digit = '7';

Character constants use single quotes.

String literals

printf("Hello, World!");

"Hello, World!" is a string literal, written using double quotes.

Compare:

'A'   // Character constant
"A"   // String literal containing A and a terminating null character

These have different types and meanings in C.

9. Operators and Punctuators

Operators perform operations on operands.

| Category | Examples | |---|---| | Arithmetic | +, -, *, /, % | | Relational | <, >, <=, >= | | Equality | ==, != | | Logical | &&, ||, ! | | Assignment | =, +=, -=, *= | | Increment/decrement | ++, -- | | Bitwise | &, |, ^, ~, <<, >> |

Punctuators help structure declarations, expressions, and statements.

Examples:

  • ; ends a statement.

  • {} enclose a compound statement.

  • () enclose function parameters or expressions.

  • are used for array indexing and declarations.

  • , separates certain declarations and arguments.

Example:

int sum = 10 + 20;

Here, + and = are operators, while ; is a punctuator.

10. Practical Example: A Program Using Different Tokens

#include <stdio.h>

int main(void) {
    int first_number = 10;
    int second_number = 20;
    int sum = first_number + second_number;

    printf("Sum = %d\n", sum);

    return 0;
}

Output:

Sum = 30

Token analysis:

Token

Category

int

Keyword

main

Identifier

first_number

Identifier

10

Integer constant

=

Operator

+

Operator

"Sum = %d\n"

String literal

return

Keyword

;

Punctuator

This program demonstrates how different token categories combine to form valid C statements.

11. Common Mistakes

  • Using a keyword as a variable name.

  • Starting an identifier with a number.

  • Using spaces or hyphens inside identifiers.

  • Assuming total, Total, and TOTAL are the same name.

  • Confusing a character constant ('A') with a string literal ("A").

  • Forgetting a semicolon after a declaration or expression statement.

  • Assuming that every symbol is an operator; braces, brackets, and semicolons serve punctuation roles.

12. Practical Exercises

Exercise checklist

0 of 6 completed

 

1. Identify tokens

Classify each token in: int result = a + 10;

 

2. Find invalid identifiers

Identify which names are invalid: total, 2value, student_name, float, my-score.

 

3. Correct the code

Fix the syntax errors in: int 2marks = 90

 

4. Case sensitivity

Write a program that declares two variables named count and Count.

 

5. Classify literals

Identify the character constant, string literal, and numeric constants in a sample program.

 

6. Write a simple program

Create a program that uses identifiers, keywords, operators, and punctuators to calculate two numbers' sum.

13. Interview Questions and Answers

Q1. What is a token in C?

A token is a basic lexical unit recognized by the compiler.

Q2. What are the main categories of C tokens?

Keywords, identifiers, constants, string literals, operators, and punctuators.

Q3. What is a keyword?

A reserved word with a predefined meaning in the C language.

Q4. What is an identifier?

A name used to identify a program entity, such as a variable or function.

Q5. Is total_marks a valid identifier?

Yes. It contains letters and an underscore and does not begin with a digit.

Q6. Is float a valid identifier?

No. float is a C keyword.

Q7. Is C case-sensitive?

Yes. value and Value are distinct identifiers.

Q8. What is the difference between 'A' and "A"?

'A' is a character constant. "A" is a string literal containing the character A followed by a null terminator.

14. Quick Revision

  • Tokens are the basic lexical units of C programs.

  • Keywords have predefined meanings and cannot be used as ordinary identifiers.

  • Identifiers name variables, functions, and other entities.

  • Identifiers cannot begin with digits or contain spaces.

  • C is case-sensitive.

  • Constants represent literal values.

  • String literals use double quotes; character constants use single quotes.

  • Operators perform operations, while punctuators organize program syntax.

15. Homework

Create a C program that:

  1. Declares two integer variables with valid identifiers.

  2. Assigns them values.

  3. Calculates their sum, difference, and product.

  4. Displays the results using printf().

  5. Identifies at least five tokens used in your own program and classifies each one.

Also write five valid and five invalid identifier examples, explaining why each invalid identifier breaks the naming rules.

Conclusion

Tokens form the building blocks of every C program. Understanding keywords, identifiers, constants, operators, and punctuators helps you recognize valid syntax, avoid naming errors, and read C code more confidently.

What is Data Types in C Language

What is Data Types in C Language

October 13, 2026

1. Introduction to Data Types

In C programming, a data type specifies the kind of value a variable can store and determines how that value can be represented and used in operations.

For example:

int age = 25;
float price = 99.50f;
char grade = 'A';
double salary = 45000.75;

Each variable uses a different data type based on the kind of information it represents.

Data types are important because they help the compiler determine storage requirements, value ranges, and the operations that can be performed on values.

Learning objectives

By the end of this module, you will be able to:

  • Understand data types in C.

  • Identify fundamental, derived, and user-defined types.

  • Use int, char, float, and double.

  • Understand signed and unsigned integer types.

  • Use sizeof() to examine storage size.

  • Understand type conversion and type casting.

  • Choose appropriate data types for practical programs.

2. Categories of Data Types in C

C data types can be organized into several categories.

C Data Types

Fundamental types

char, int, float, double, void

Derived types

Arrays, pointers, and function types

User-defined types

Structures, unions, and enumerations

Type aliases

typedef creates an alternative name for a type.

These categories describe common ways C types are organized. typedef does not create a completely new distinct type; it introduces a type alias.

3. Fundamental Data Types

A. Integer type: int

The int type stores whole-number values.

#include <stdio.h>

int main(void) {
    int age = 25;
    int temperature = -10;
    int quantity = 100;

    printf("Age: %d\n", age);
    printf("Temperature: %d\n", temperature);
    printf("Quantity: %d\n", quantity);

    return 0;
}

Output:

Age: 25
Temperature: -10
Quantity: 100

Use int for values such as counts, ages, and quantities when its range is sufficient.

B. Character type: char

The char type stores a single byte-sized character unit. On typical systems, it is used to represent characters such as letters, digits, and punctuation.

#include <stdio.h>

int main(void) {
    char grade = 'A';
    char symbol = '#';

    printf("Grade: %c\n", grade);
    printf("Symbol: %c\n", symbol);

    return 0;
}

Output:

Grade: A
Symbol: #

Use single quotes for character constants:

char letter = 'A';

By contrast, "A" is a string literal, not a character constant.

Important: C's char stores one byte, which is not necessarily one byte of Unicode text. A character outside the basic character set may require multiple bytes in a multibyte encoding.

C. Floating-point type: float

The float type represents floating-point values, including values with fractional parts.

#include <stdio.h>

int main(void) {
    float price = 99.50f;
    float temperature = 36.5f;

    printf("Price: %.2f\n", price);
    printf("Temperature: %.1f\n", temperature);

    return 0;
}

Output:

Price: 99.50
Temperature: 36.5

The f suffix in 99.50f makes the literal a float constant.

D. Double-precision type: double

The double type generally provides more precision than float.

#include <stdio.h>

int main(void) {
    double pi = 3.141592653589793;
    double distance = 12345.6789;

    printf("Pi: %.6f\n", pi);
    printf("Distance: %.4f\n", distance);

    return 0;
}

Output:

Pi: 3.141593
Distance: 12345.6789

Use double for calculations where greater floating-point precision is useful.

4. Comparing Fundamental Data Types

The following are typical characteristics, not universal size guarantees.

Data type

Purpose

Common size on modern systems

char

Character-sized data

1 byte

short

Small-range integer

2 bytes

int

General-purpose integer

4 bytes

long

Larger-range integer

4 or 8 bytes

long long

Extended-range integer

8 bytes

float

Floating-point value

4 bytes

double

Higher-precision floating-point value

8 bytes

long double

Extended floating-point type

Platform-dependent

The C standard specifies minimum ranges and relationships between certain types, but it does not require every implementation to use the exact sizes shown above.

5. Signed and Unsigned Data Types

Integer types can have signed or unsigned forms.

  • Signed types represent negative and non-negative values.

  • Unsigned types represent only non-negative values.

Example:

#include <stdio.h>

int main(void) {
    signed int temperature = -5;
    unsigned int items = 50;

    printf("Temperature: %d\n", temperature);
    printf("Items: %u\n", items);

    return 0;
}

Output:

Temperature: -5
Items: 50

For integer types other than char, signedness is generally signed by default unless unsigned is specified.

Be careful when mixing signed and unsigned values in comparisons or arithmetic. The usual arithmetic conversions can produce surprising results, especially when negative values are converted to unsigned types.

6. The sizeof() Operator

The sizeof operator returns the size of a type or object in bytes. Its result has type size_t, so %zu is the appropriate printf() format specifier.

#include <stdio.h>

int main(void) {
    printf("Size of char: %zu byte(s)\n", sizeof(char));
    printf("Size of int: %zu byte(s)\n", sizeof(int));
    printf("Size of float: %zu byte(s)\n", sizeof(float));
    printf("Size of double: %zu byte(s)\n", sizeof(double));

    return 0;
}

A typical output might be:

Size of char: 1 byte(s)
Size of int: 4 byte(s)
Size of float: 4 byte(s)
Size of double: 8 byte(s)

Your results may differ for some types depending on the compiler and platform.

Key point: sizeof(char) is always 1 by definition. A C byte is the size of a character storage unit, and it is not guaranteed to contain exactly eight bits.

7. Type Modifiers in C

Type modifiers adjust certain integer or floating-point types.

Common modifiers include:

  • signed

  • unsigned

  • short

  • long

Examples:

short int small_number = 100;
long int population = 1000000L;
long long int large_number = 9000000000LL;
unsigned int count = 500U;
long double precise_value = 3.141592653589793L;

Modifiers can change the range and, depending on the implementation, the size of a type.

For printf(), use matching format specifiers for the actual type. For example, %lld is used for long long int, %u for unsigned int, and %Lf for long double.

8. Type Conversion in C

Type conversion happens when a value of one type is converted to another type.

There are two common forms.

A. Implicit conversion

The compiler performs a conversion automatically when required by an expression or assignment.

#include <stdio.h>

int main(void) {
    int number = 10;
    double result = number;

    printf("Result: %.2f\n", result);

    return 0;
}

Output:

Result: 10.00

Here, the integer value is converted to double.

B. Explicit conversion (type casting)

The programmer requests a conversion using a cast.

#include <stdio.h>

int main(void) {
    int a = 7;
    int b = 2;

    double result = (double)a / b;

    printf("Result: %.2f\n", result);

    return 0;
}

Output:

Result: 3.50

Without the cast, a / b would perform integer division and produce 3. Casting a to double makes the division floating-point.

9. Derived Data Types

Derived types are formed using other types.

A. Arrays

An array stores multiple elements of the same type.

int marks[3] = {80, 90, 75};

Here, marks is an array of three integers.

B. Pointers

A pointer stores the address of an object or function, depending on its pointer type.

int age = 25;
int *ptr = &age;

Here, ptr is a pointer to int.

C. Function types

Functions have types determined by their return types and parameter types.

int add(int a, int b) {
    return a + b;
}

This function returns an int and accepts two int parameters.

10. User-Defined Types

C provides language features that allow programmers to define structured or named types.

A. Structure (struct)

A structure groups related members, potentially of different types.

struct Student {
    int id;
    char grade;
};

B. Union (union)

A union allows its members to share the same storage region.

union Data {
    int number;
    float value;
};

C. Enumeration (enum)

An enumeration defines named integer constants.

enum Day {
    MONDAY,
    TUESDAY,
    WEDNESDAY
};

D. Type alias (typedef)

typedef introduces an alternative name for an existing type.

typedef unsigned int uint;

uint count = 100;

These features help make complex programs easier to organize and read.

11. Practical Example: Student Information

This program uses several data types to store and display student information.

#include <stdio.h>

int main(void) {
    int student_id = 101;
    char grade = 'A';
    float attendance = 92.5f;
    double percentage = 88.75;

    printf("Student ID: %d\n", student_id);
    printf("Grade: %c\n", grade);
    printf("Attendance: %.1f%%\n", attendance);
    printf("Percentage: %.2f%%\n", percentage);

    return 0;
}

Output:

Student ID: 101
Grade: A
Attendance: 92.5%
Percentage: 88.75%

This example demonstrates how selecting appropriate data types helps represent different kinds of information.

12. Common Mistakes

Mistake

Explanation

Using %d for a float in printf()

Use %f for double arguments and %f for float values promoted through variadic calls such as printf().

Using %f with scanf() for a double

Use %lf for a double destination in scanf().

Assuming every int is four bytes

Sizes depend on the implementation.

Expecting 7 / 2 to equal 3.5

Integer division produces 3.

Ignoring narrowing conversions

Converting to a type with a smaller range or precision can lose information.

Using unsigned types for negative values

Negative values converted to unsigned types do not remain negative.

Assuming floating-point values are exact

Many decimal fractions cannot be represented exactly in binary floating-point.

13. Practical Exercises

Exercise checklist

0 of 6 completed

 

1. Declare different data types

Declare variables using int, char, float, and double, then display their values.

 

2. Explore sizeof()

Print the sizes of char, short, int, long, long long, float, double, and long double.

 

3. Calculate an average

Read three integers and calculate their average as a floating-point value.

 

4. Practice type casting

Divide two integers and display both the integer result and floating-point result.

 

5. Use signed and unsigned

Declare signed and unsigned integers and explore valid input ranges.

 

6. Create a student record

Use a structure to store a student ID, grade, and percentage.

14. Interview Questions and Answers

Q1. What is a data type in C?

A data type defines the kind of value an object can represent and influences its storage, range, and operations.

Q2. What are the fundamental data types in C?

Common fundamental types include char, integer types, floating-point types, and void.

Q3. What is the difference between float and double?

double generally provides greater precision than float, although exact representations and sizes depend on the implementation.

Q4. What does sizeof() do?

It returns the size in bytes of a type or object.

Q5. What is type casting?

Type casting explicitly requests a conversion from one type to another.

Q6. What is the difference between signed and unsigned integers?

Signed integers can represent negative values, while unsigned integers represent only non-negative values.

Q7. What is the result of 7 / 2 when both operands are integers?

The result is 3, because integer division discards the fractional part.

Q8. What is the difference between a structure and a union?

A structure provides separate storage for its members, while a union shares storage among its members.

15. Quick Revision

  • Data types define the kinds of values variables and objects can represent.

  • int represents integer values.

  • char represents a character-sized unit.

  • float and double represent floating-point values.

  • Signed and unsigned types differ in their ranges.

  • sizeof() returns an object's or type's size in bytes.

  • Type conversion can be implicit or explicit.

  • Arrays, pointers, structures, unions, and enumerations support more complex data organization.

16. Homework

Create a Student Result Management Program that:

  1. Stores a student's ID using an integer type.

  2. Stores a grade using char.

  3. Stores attendance using float.

  4. Stores percentage using double.

  5. Displays each value using the correct format specifier.

  6. Calculates the average of three subject marks without accidentally performing integer division.

  7. Uses sizeof() to print the sizes of selected variables.

Make sure the program validates user input and does not assume that every C implementation uses the same data type sizes.

Conclusion

Data types are a foundation of C programming. Choosing the correct type improves clarity, helps prevent errors, and ensures that values are represented appropriately. Understanding type conversion, storage sizes, and format specifiers will make your programs more reliable.

←
Post 3 of 15
→