What is variable in C language? An interview question

Variable is the name of a small memory part that stores data as per program instructed. It may be an integer, float or character.

C is a strong type language and it has some primitive data type as well as drive data types.

How to declare a variable?

You can define variables in C easily. Just put the data type name and then name of variable like below:

int a,b,c;
float p,q,r;
char m,n;

Here, [a,b,c] are variables that can store any integer values and perform operations to store integer result. Similarly, float as well as character variables can store float and char values easily.

We need variables to perform arithmetic and logical operations. For example, if you want to add 2 integer numbers, you need at least 3 integer variables – 2 for taking values from user and 1 for showing a result.

Let’s try to understand with the below code:

int a,b,c;
/*Here a and b both will use to get values 
from user*/
//c will be used to put the result
//taking input values in a and b
print c;

Variable declaration rules

  • You can not start any user-defined variable from underscore (_)
  • It can not start with a number like 0,5,9 etc.
  • you can not user any special symbols
  • Do not put white space between two characters or words to make a single variable. e.g. int age group; (this is wrong it would be like int age_group;)

Hope that you understand about C variables and how we can declare them. You can also read What is a C programming language [exam oriented answer]

You can also refer Let Us C for more information on C Programming.

Don’t forget to share this post in social family and ask your questions in the comment section below.

Leave a Comment

Show Buttons
Hide Buttons