Author Topic: i got a question about c++  (Read 1376 times)

0 Members and 1 Guest are viewing this topic.

Offline aldo_14

  • Gunnery Control
  • 213
i got a question about c++
Quote
Originally posted by Fear
i understand the const now,though i still cant undetstand static operator . what is supose to do change  1 int to another int?


No, just to ensure whatever result is returned is treated as an int.  i.e. you don't know what you get back, but the cast 'turns' it (logically) into an int value.

i.e.
Lets say the String 'blah'
is
1001 1110
in memory (its not, that's far too small and short a value....but ne'erming ;) )

Now -  there's nothing 'stored' which says that binary value is a String - the only thing that indicates that, is that you reference it in the program as a String variable.

So, if you cast to an int, the program is simply reading that same memory, in a different way.  Instead of working out 1001 1110 is 'blah' (as it would with a String) it's reading it as its integer value.

So - it doesn't change what's stored, but how the program 'looks' at it.  In the case before, it's ensuring that whatever result that operation gives, it'll be modified and referenced as an int value.

 

Offline Fear

  • 26
i got a question about c++
so all its change is how the program will treat to it? dam what use this bring :p

 

Offline aldo_14

  • Gunnery Control
  • 213
i got a question about c++
Quote
Originally posted by Fear
so all its change is how the program will treat to it? dam what use this bring :p


Well, yeah.  But bear in mind you can still make changes to that memory space - i.e. if you have 1 pointer referencing it as an int, and one as a String, then decrementing the 'int' reference will affect what you get as a String value.  Etc.

 

Offline Fear

  • 26
i got a question about c++
got it... but i cant think of the situtasion that i will have to use it.

  

Offline vyper

  • 210
  • The Sexy Scotsman
"But you live, you learn.  Unless you die.  Then you're ****ed." - aldo14

 

Offline Fear

  • 26
i got a question about c++
its free?!

 

Offline vyper

  • 210
  • The Sexy Scotsman
i got a question about c++
The Dive Into ones are.
"But you live, you learn.  Unless you die.  Then you're ****ed." - aldo14