Variables in C

A variable is a symbolic name that refers to a location in memory where data is stored. It can be used for various purposes and its value can be changed.
It is a way of using symbols to identify memory locations so that they can be accessed and manipulated more conveniently.

Type variable_list;

The example of declaring the variable is given below:int a;
float b;
char c;


Here a, b, c are variables. The int, float, char are the data types.

Alternatively, we can assign values to the variables when we declare them, as shown below:


int a=10,b=20;//declaring 2 variable of integer type
float f=20.8;
char c='A';

Rules for defining variables

  • A variable is a name that can consist of letters, numbers, and underscores. 
  • A variable name must begin with a letter or an underscore, not a number. 
  • A variable name cannot contain any spaces. 
  • A variable name cannot be the same as any of the reserved words or keywords in the programming language, such as int, float, etc.
Valid variable names:
int a;
int _ab;
int a30;

Invalid variable names:

int 2;
int a b;
int long;

Comments

Popular posts from this blog

Introduction To C

First C Program

Compilation process in c