Tuesday, 17 May 2011

Variables or What are Variables?

Variable is a space in the computer's memory set aside for a certain kind of data and given a name for easy reference.
Variables are used so that the same space in memory can hold different values at different times.


Syntax:


datatype var_name;


where, datatype are int(for integers), float(for fractional values), char(for character), etc


Example Code:


#include<stdio.h>
#include<conio.h>
void main()
{
//1-Assign a variable or variables first!
int a,b,sum;
//2-Now Assign a value in it! 
a=5;
b=10;
sum=a+b;
printf("The sum of %d and %d is %d",a,b,sum);
getch();
}


You can also give the value to variable as:
int a=5,b=10,sum=a+b;


This step is called "Initialization".




If you have any kind of question, just ask me freely!

0 comments:

Post a Comment