Saturday, July 2, 2016

Variables

In programming, a variable is a container (storage area) to hold data.
To indicate the storage area, each variable should be given a unique name (identifier). Variable names are just the symbolic representation of a memory location. 
example: int x=10;
here x is a variable of integer type, the variable is holding 10 in above example. The value of a variable can be changed.

Rules:

1.   A variable name can have 
  • letters (both uppercase and lowercase letters), 
  • digits and 
  • underscore only.

2.   The first letter of a variable should be either a letter or an underscore. However, it is discouraged to start variable name with an underscore. It is because variable name that starts with an underscore can conflict with system name and may cause error.
3.   There is no rule on how long a variable can be. However, the first 31 characters of a variable are discriminated by the compiler. So, the first 31 letters of two variables in a program should be different.
C is a strongly typed language. Which means, the type of a variable cannot be changed. Suppose, you declared an integer type variable. You cannot store character or a decimal number in that variable. Visit this page to learn more about different types of data a variable can store.



No comments:

Post a Comment