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:

At 14 February 2018 at 03:26 , Blogger Unknown said...

helpful blog thanks for sharing this blog
spring mvc interview questions
machine learning online training
servlet interview questions
mytectra.in
wcf interview questions

 
At 1 August 2018 at 23:22 , Blogger Unknown said...

• 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

 
At 31 October 2018 at 01:47 , Blogger afiah b said...

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

 
At 31 October 2018 at 04:18 , Blogger Unknown said...

I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thx again!

Data Science course in Chennai | Best Data Science course in Chennai
Data science course in bangalore | Best Data Science course in Bangalore
Data science course in pune | Data Science Course institute in Pune
Data science online course | Online Data Science certification course-Gangboard
Data Science Interview questions and answers

 
At 8 November 2018 at 00:34 , Blogger Unknown said...

I am really happy with your blog because your article is very unique and powerful for new reader.
Click here:
selenium training in chennai | selenium course in chennai
selenium training in bangalore | selenium course in bangalore
selenium training in Pune | selenium course in pune | selenium class in pune
selenium training in Pune | selenium course in pune | selenium class in pune
selenium online training | selenium training online | online training on selenium



 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home