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 any variable 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

a=5;
b=6;
//taking input values in a and b
c=a+b;
print c;

Variable declaration rules

  • You can not start any user-defined variable from underscore (_)
  • a variable can not start with a number like 0,5,9 etc.
  • you can not start a variable with 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]

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

Leave a Comment

error: Don\'t make piracy - Write your own content :)