Skip to main content

Command Palette

Search for a command to run...

6.Tokens in C

Basic Terminologies in C Programming

Published
2 min read
6.Tokens in C

Identifiers in C

In C programming, identifiers are the names used to identify variables, functions, arrays, structures, or any other user-defined items. It is a name that uniquely identifies a program element and can be used to refer to it later in the program.

// Creating a variable

int val = 10;

// Creating a function

void func() {}

In the above code snippet, "val" and "func" are identifiers.

Variable

A variable is a name given to a memory location used to store data.

  • The value stored in a variable can change during program execution

  • Variables are used to store intermediate results

Rules for Naming Variables

While naming variables in C, the following rules must be followed:

1️⃣ A variable name must start with a letter (a–z or A–Z)
2️⃣ It can contain letters, digits, and underscore (_)
3️⃣ It cannot start with a digit
4️⃣ No spaces are allowed in variable names
5️⃣ Special symbols like @, #, %, & are not allowed
6️⃣ Variable names cannot be keywords
7️⃣ C is case-sensitive (total and Total are different)

Valid Variable Names

  • sum

  • total_marks

  • count1

  • result

Invalid Variable Names

  • 1count (starts with digit)

  • total marks (space not allowed)

  • float (keyword)

  • @value (special character)

Constant

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

  • Once defined, its value remains fixed

  • Constants are used for values that should not be modified

  • Example in words:
    Value of PI, number of days in a week, etc.

Keywords

Keywords are reserved words in C programming.

  • Each keyword has a predefined meaning

  • Keywords cannot be used as identifiers

C language has 32 keywords

Program

A program is a collection of instructions written to solve a specific problem.

  • A program follows a logical sequence

  • It takes input, processes it, and produces output

Statement

A statement is a single instruction given to the computer.

  • Statements tell the computer what to do

  • Each statement performs a specific task

Comment

A comment is used to explain the program.

  • Comments are ignored by the compiler

  • They are written for human understanding

Syntax

Syntax refers to the rules of writing a program.

  • C programs must follow correct syntax

  • If syntax rules are violated, errors occur

Errors

An error is a mistake in a program that prevents correct execution.

Common types of errors:

  • Syntax errors

  • Logical errors

  • Runtime errors