Variables In C Language | How To Use Variables In C Language | Define Variables In C Program

Variables, Data Types, and Operators in C

In this chapter, we will explore variables, data types, and operators in C programming. These fundamental concepts are essential for storing, manipulating, and processing data in a C program.

3.1 What are Variables?

A variable is a name given to a memory location where data is stored. Variables hold different types of values, such as numbers, characters, or strings, and their values can change during program execution.

Declaring a Variable in C

To use a variable, we must declare it first by specifying its data type and name.

data_type variable_name;

Example:

int age;    // Declares a variable named ‘age’ of type integer

float price; // Declares a variable named ‘price’ of type float

char grade;  // Declares a variable named ‘grade’ of type char

3.2 Rules for Naming Variables

✔️ A variable name can contain letters, digits, and underscores (_).
✔️ It must start with a letter or an underscore (e.g., _count, num1).
✔️ It cannot be a C keyword (e.g., int, return, float).
✔️ C is case-sensitive (number and Number are different variables).

Leave a Comment

Your email address will not be published. Required fields are marked *