C Programming/C Basics

C Variable & Constant

Updated on January 8, 2026
1 min read

C Variables, Constants, and Literals (Easy Explanation)

In C language, variables, constants, and literals are used to store and represent data in a program.

Think of them like containers and values in real life.

EASY LEVEL EXPLANATION (Beginner Friendly)

1. Variables in C (Easy)

variable is a container that stores data, and its value can change while the program is running.

Real-Life Example

water bottle:

  • You can fill it
  • You can empty it
  • You can refill it

The bottle is the variable, and the water inside is the value.

Example in C

int age = 18;
  • age is a variable
  • 18 is the value

The value can change later:

age = 20;

2. Constants in C (Easy)

constant is a value that cannot be changed once it is set.

Real-Life Example

date of birth:

  • It never changes

Example in C

const int BIRTH_YEAR = 2010;

Another way:

#define MAX 100

3. Literals in C (Easy)

literal is a fixed value written directly in the program.

Real-Life Example

A number written on paper like 10 or 50.

Examples

10        // integer literal
3.14      // floating literal
'A'       // character literal
"Hello"   // string literal

EXPERT LEVEL EXPLANATION (Conceptual & Technical)

1. Variables in C (Expert)

variable is a named memory location used to store data whose value can be modified during program execution.

Technical Details

  • Memory is allocated at runtime
  • Variable refers to a fixed memory address
  • Only the stored value changes, not the address

Example:

int count = 5;
count = 10;

Here, count refers to the same memory location, but its value changes from 5 to 10.

2. Constants in C (Expert)

constant is a read-only memory location whose value cannot be altered after initialization.

Using const

const int MAX_SIZE = 100;
  • Memory is allocated
  • Any modification causes a compile-time error

Using #define

#define PI 3.14
  • No memory allocation
  • Value replaced during preprocessing

3. Literals in C (Expert)

literal represents a constant value that appears directly in source code.

Characteristics

  • Not associated with a variable name
  • Stored temporarily or optimized by compiler
  • Used to assign values to variables

Example:

int x = 10;     // 10 is a literal
char ch = 'A'; // 'A' is a literal

Difference Between Variable, Constant, and Literal

TermMeaningMutabilityExample
VariableStores dataCan changeint x = 5;
ConstantFixed valueCannot changeconst int y = 10;
LiteralActual valueFixed10"Hi"

Conclusion (Easy + Expert)

  • Variables store values that can change
  • Constants store fixed, protected values
  • Literals are the actual values written in code

These concepts are the foundation of C programming and are essential for writing correct, efficient, and maintainable programs.

C Variable & Constant | C Programming | Learn Syntax