Find us on Google+ C Variables - Invatac - Technology Blog

Pages - Menu

Sunday, 9 September 2012

C Variables



Variable

Variables are used to store data. It is actually referring to memory address in computer. Variable is assigning a storage location.

Rules For Declaring a C Variable

Variable should have a name.We call it as a Variable name. If we want to declare a C Variable we have to follow some rules.

  • We should not use "Keywords" as a variable name.
     
  • First  letter of variable name should not be a number, but we can use numbers, letters, and underscore ( _ ) for declaring a variable name.
  • Maximum length of a C Variable is 247 characters. So please make sure you are declaring a small variable and a meaningful name
A good programmer will create a meaningful variable name, so anyone who are reading codes can understand what the programmer thought about.

Why we are declaring Variable?

Main reason behind is that we should tell C Compiler that we are using these Variables for storing our program's data. So we are declaring variables before we use them in our program, and by that way we can tell compiler the type of variable we are declaring. I think you got the answer of the question.

How we can declare a Variable

  • We should find a meaningful name and should satisfy our rules
  • Assign the data type (type of value we are going to assign it in our variable) and as this is a statement we should end with a semicolon 
we can try to declare an Integer Variable

int x;
int variable_c;

Here we declared two Variables 1st one : x and other : variable_c
both can contain only Integer data values, so we assigned it as "int"

How we can Initialize a C Variable?

it is not a big deal to initialize a c variable, C allows us to initialize variable at the time of declaration itself :
Let's check an Example

int x=10;

char invatac='C';

we assigned value 10 to variable 'x' and character c to variable 'invatac'

Hope this tutorial will helpful for you, Thanks for listening

Rahul Babu RAbout Me
I am a computer student looking for make my own name in the field of technology. Please add my to your circles.




No comments:

Post a Comment