Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Saturday, 1 June 2019

Variables in C


A variable is the name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times.

It is a way to represent memory location through a symbol so that it can be easily identified.

Let's see the syntax to declare a variable:

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 is the data types.

We can also provide values while declaring the variables as given 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 can have alphabets, digits, and underscore.
A variable name can start with the alphabet, and underscore only. It can't start with a digit.
No whitespace is allowed within the variable name.
A variable name must not be any reserved word or keyword, e.g. int, float, etc.

Valid variable names:
int a;  
int _ab;  
int a30;  

Invalid variable names:
int 2;  
int a b;  
int long;  

0 comments:

Post a Comment