15 April 2013


ok remember this that for the computer to process data it has to be in RAM.if it is in secondary storage then it has to be brought in primary memory(RAM) so that processor can fetch and execute it.
ok so how will you store data in primary memory so that processor can use it and after that how will you
identify your data?

for  every thing on earth can be identified by a name.same happens here.. everything you will use in your program whether it is data,constants,functions etc there is a identifier for you.
there are some special identifiers which are predefined and their functionality cannot be changed.These identifiers are called keywords.we can use any identifier except keywords for identifying our objects or data

int main(){
int a=2
float b =2.3
double c =2.344
// a,b,c are called identifiers.They are used to identify your data.Each identified object is stored in unique //memory location.so 2 ,2.3 ,2.344 will be stored in different locations and will take different amount of memory.to access 2 you can use a .similarly for 2.3,2.344 you can use b and c.

[caption id="attachment_161" align="alignleft" width="300" caption="storage for different datatypes"]<a href="http://localhost:8080/doandget/wp-content/uploads/2011/02/datatypes.png"><img src="http://localhost:8080/doandget/wp-content/uploads/2011/02/datatypes-300x111.png" alt="" title="datatypes" width="300" height="111" class="size-medium wp-image-161" /></a>[/caption]

so i can only use a-z as identifiers ?
no there are some set rules which you have to  use for your identifiers..
1. an identifier must start with a letter or underscore and it may not have a space or hyphen.
2. we cannot use reserve words or keywords such as int ,char ,while etc for identifiers
3.Identifiers are case sensitive. The compiler considers upper and lowercase characters to be different.
4.$ can be used as a  valid character in an identifier as long as it is not the first character.
5.255 significant characters can be used in identifier name.
a,A; //valid
first-name // invalid
2names //invalid
first name //invalid
int  //invalid
INT //valid
$x  //invalid
x$  //valid
_score //valid
_ //valid
____________  //valid
a*b //invalid
--------->; //invalid
a--------->; //invalid
INIT_MAX //valid
int main(){
datatype a,A; // valid
datatype first-name // invalid - not allowed
datatype 2names //  invalid starting with number
datatype first name ;// invalid space not allowed
datatype datatype ; // invalid cant use reserved words
datatype INT ;// valid INT is not a reserved word .UPPERCASE
datatype CHAR,WHILE,DO,ELSE,IF,ANY UPPERCASE // valid all are uppercase
datatype $x ; //invalid starting with $
datatype x$ ; // valid
datatype _score; // valid
datatype _; // valid
datatype ____________ ; //valid
datatype a*b; // invalid any special character except _,$ is not allowed
datatype --------->; // invalid same reason
datatype a--------->; //invalid same reason
datatype INIT_MAX //valid
datatype Int;//valid it is Int not int
datatype while,else,if  //invalid while,else ,if is a keyword
if you will look at the rules then you probably identify why they are valid or invalid.The sequence of characters after datatype are identifiers.The combination datatype+identifier is called declaration.
so int x means reserve 2 bytes of memory for storing integer data .Ok there can be something already present in that memory .it is called garbage.so
int x ;//x means some garbage value
int x=5 ;// reserve two bytes of memory and erase the old content and put 5 in it.so x will represent 5 now.

note that some identifier rules may be compiler specific
also note that memory allocated for storing data of different datatypes is machine dependent.
for eg my machine allocates 2 bytes of memory for storing int type data.it may be possible that your machine will allocate 4 bytes of memory for storing int data.