variables

Questions about programming languages and debugging
Post Reply
ss1
On the way to fame!
On the way to fame!
Posts: 45
Joined: 25 Nov 2006, 17:00
17

variables

Post by ss1 »

hey everyone whats a variable a constant and a data type i really need to know?

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

a constant is a permanent value, the opposite are variables...the value of variables can be changed within the program.
datatypes set the kind of the value of a variable or a constant, letters or numbers for example.

here are the common datatypes:

integer-types
byte //numbers from -128 to 127 (size 8 bit)
short //numbers from -32.768 to 32.767 (size 16 bit)
int //numbers from -2.147.483.648 to 2.147.483.647 (size 32 bit)
long //numbers from -9.223.372.036.854.775.808 to 9.223.372.036.854.775.807 (size 64 bit)

you might wonder now why there are different types of integer variables...because the long-one covers all the ranges of the other ones anyway, right? well, for every variable memory space is assigned, and that is what the bit-values above mean....example:

Code: Select all

long x;
x = 50;
-------------
byte x;
x = 50;
in both cases the variable x has the value 50, but in the first case it has the datatype long...so 64 bit of memory is reserved for this variable when the program runs.
in the second case the datatype is byte and only 8 bit of memory will be reserved.
by picking the proper datatype you can decrease the memory usage of your program, which saves system resources and also increases the speed of your program.

floating point-types
float //numbers from 1.7e-308 to 1.7e+308 (size 32 bit)
double //numbers from 3.4e-38 to 3.4e+38 (size 64 bit)

both types are used for well, floating point numbers...^^ let's say you divide 3 by 2...the result is a floating point number. don't wonder about the strange values like "1.7e-308", it's just easier to write it this way because the real value would have some hundred numbers like 0,00000000000000.....1
best use the double-one and you're on the safe side.

characters
char //any kind of character
a character can be a number too, but it's not handled like a number then, it's handled as text.

boolean
boolean //true or false
for example:
1=1 //true
2=1 //false


nice to see you're interested in programming btw...

:wink:

User avatar
floodhound2
∑lectronic counselor
∑lectronic counselor
Posts: 2117
Joined: 03 Sep 2006, 16:00
17
Location: 127.0.0.1
Contact:

Post by floodhound2 »

Damn Bad_brain I could not have said it better. You hit all the high spots without confusing noobs. Great post and Great question SS1.

PEACE

8)
₣£ΘΘĐĦΘŮŇĐ

User avatar
bennybill
suck-o-fied!
suck-o-fied!
Posts: 69
Joined: 21 Nov 2006, 17:00
17
Contact:

Post by bennybill »

Yeh B_B even i understood that :lol: man ur 1 smart guy.

B3^

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

Too much java, huh?? that's java specific datatypes,although they are same in almost all the languages but still there's no byte, boolean in c,c++ and assembly has different datatypes altogether, php has internal type casting!!!

Anyway as b_b already said variables are a small part of memory reserved which can be used later in programs, once you define variable you have given a name to a memory location.. for example you can call 0xFF4BC12 location 'a' and later store any value in that location and perform operations... a constant is same but it wont let you change its value later in program, so as name says its value remains constant, and a variable's value can vary.

Btw no doubt b_b is a smartass :wink:

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

hehe...yeah, those are Java types.....but well, in most OOP languages the forms of datatypes are at least similar. my languages are Java and Perl, Perl variables are too language specific....that's why I picked Java as example... :wink:

User avatar
bennybill
suck-o-fied!
suck-o-fied!
Posts: 69
Joined: 21 Nov 2006, 17:00
17
Contact:

Post by bennybill »

I wasnt saying B_B was dumb or anything if thats wat u are suggestion???? :?

User avatar
floodhound2
∑lectronic counselor
∑lectronic counselor
Posts: 2117
Joined: 03 Sep 2006, 16:00
17
Location: 127.0.0.1
Contact:

Post by floodhound2 »

Nah you just paranoid no one thinks you thought that. Lay off the marijuana bro…

I kid I kid it is cool man

Peace
₣£ΘΘĐĦΘŮŇĐ

User avatar
bennybill
suck-o-fied!
suck-o-fied!
Posts: 69
Joined: 21 Nov 2006, 17:00
17
Contact:

Post by bennybill »

L0L soz big man 8)

B3^

Post Reply