Friday, 8 March 2013

Variables


Variables: A variable is a symbolic name of a location in the computer's memory. In this variable, a value can be stored and this can be used in the program. The value of a variable may change during the program execution. Only one value can be stored at a time in it. In a variable you can store integer value or float value, character value or string names according to the requirement. As we know that a variable is an identifier of certain data. Every variable must have a name and a data type. A data type is the type of data which is to be stored in a variable. It can be an integer, floating, character or string name values. These values can be assigned to the variable using assignment operator: = (equal to)
Example of variable: sum=5+10; Here sum is a variable and 5 & 10 are two integer constant values. + And = are two operators. Semicolon (;) is used in the end of every C statement. This tells that it is end of statement.

Rules for naming variables: 1) a variable must be unique in a program’s block.
2) A variable name can contain only alphabets, digits and underscore. No any other symbol can be used.
3) The variable name must begin with a letter or an underscore.
4) A variable name must not start with a digit.
5) C language is a case sensitive language. It means upper case and lower case letters are different variable.
6) A variable name must not contain any white space. The white space includes tab, spacebar and new line.
7) It can’t be a C language keyword or reserve word. As we know that C is a case sensitive language and we can use different case of keywords as variable name.
8) A variable name cannot use a symbol in naming.
9) Some valid examples are: a, box, tab10, roll_no, Roll_no, _abc, For.
10) Some invalid examples are: 10tab, for, ab$c, roll no.
11) The length of variable name should be of 31 characters. If it is more than 31 characters then compiler will not generate any error but it will recognize only first 31 characters.


Where to declare Variables: There are two kinds of place in which declarations can be made.

  1. One place is outside all of the functions. That is, in the space between function definitions. (After the #include lines, for example.) Variables declared here are called global variables. They are also called static and external variables in special cases.)
#include <stdio.h>

int globalinteger;              /* Here! outside {} */

float global_floating_point;

main ()

{
}
2.      The other place where declarations can be made is following the opening brace, {}, of a block. Variables of this kind only work inside their braces {} and are often called local variables. Another name for them is automatic variables.
main ()

 { int a;
   float x,y,z;

 /* statements */

 }

5 comments:

  1. • Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating IOT Online Training

    ReplyDelete
  2. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
    Java interview questions and answers

    Java training in Chennai | Java training institute in Chennai | Java course in Chennai

    Java training in Bangalore | Java training institute in Bangalore | Java course in Bangalore

    Java interview questions and answers

    ReplyDelete