I am new in programming. I got problems on Variable and Constant? I want to know about the range and why there must be a range for such as int, char,and etc....I hope i can get answers here. Thank for helping.
What is Variable and Constant ?
Page 1 of 14 Replies  306 Views  Last Post: 13 February 2011  08:18 AM
Replies To: What is Variable and Constant ?
#2
Re: What is Variable and Constant ?
Posted 12 February 2011  08:47 PM
what? ill try to help but im not sure what you asking
a variable is place to store data of almost any kind. a constant is data which doesn't change there are constants that are declared like variables also.
these are all variables and there values can change. depending on there size they can hold different ranges of information. an int is typically 4 bytes and a byte is typically 8 bits so it can store 2^32 different sets of data. now the numerical range is based on interpretation of this data. in the case of int the highest order bit is seen as the sign and 0 is all bits false. this gives int a range of 2^31 to 2^311. char is almost always a byte and as a byte is typically 8 bits a char has 2^8 different values. it follows the same rules as int for it's range so it has a range of 2^7 to 2^71 or 128127. for unsigned values it's even simpler, they dont have a sign so there range is simply 0 to 2 to the power of there size in bits. take unsigned int for example it has a range of 0 to 2^321. floats and double arekinda wiredreally wired. you can look up some stuff on them on google if you need to. if you need to know there range look at this
a variable is place to store data of almost any kind. a constant is data which doesn't change there are constants that are declared like variables also.
"this is a constant" 10 //this is a constant const int x = 30; //this is a constant that can be used like a variable
int a; char b; short c; float i; double j; char* k; unsigned int x; unsigned char y; unsigned short z;
these are all variables and there values can change. depending on there size they can hold different ranges of information. an int is typically 4 bytes and a byte is typically 8 bits so it can store 2^32 different sets of data. now the numerical range is based on interpretation of this data. in the case of int the highest order bit is seen as the sign and 0 is all bits false. this gives int a range of 2^31 to 2^311. char is almost always a byte and as a byte is typically 8 bits a char has 2^8 different values. it follows the same rules as int for it's range so it has a range of 2^7 to 2^71 or 128127. for unsigned values it's even simpler, they dont have a sign so there range is simply 0 to 2 to the power of there size in bits. take unsigned int for example it has a range of 0 to 2^321. floats and double are
#3
Re: What is Variable and Constant ?
Posted 12 February 2011  09:09 PM
Also to add about the range. The variable will be stored in memory and by knowing the maxium size the computer knows how much memory space it needs to allocate for it.
#4
Re: What is Variable and Constant ?
Posted 13 February 2011  04:39 AM
thomastan, on 13 February 2011  04:09 AM, said:
I am new in programming. I got problems on Variable and Constant?
thomastan, on 13 February 2011  04:09 AM, said:
I want to know about the range and why there must be a range for such as int, char
if you do happen to need numbers which have thousands or millions of digits, then there are ways around it, but I very much doubt this will be a problem for you while you're still learning.
#5
Re: What is Variable and Constant ?
Posted 13 February 2011  08:18 AM
Thanks alot. You guys help me a lot. Now i understand. And do you know which website that i can learn c++ instead of buying a programming reference book. Because those reference books in Malaysia are so expensive.
Page 1 of 1
