+ 1

Discovering new things in C++

I was wondering about this: int main(){ int a = 0x0; return 0; } this is accepted in C++. why is this? Is it because it represents an address? I know next to nothing about computer architecture, but "zero times something" seems to be the way memory addresses are represented. If this is true, then what kinds of things can be done using this? Are there ways to target certain aspects of a computer using specific hexadecimal numbers in this way?

29th Jun 2017, 3:47 AM
21kHzBANK21kHZ
21kHzBANK21kHZ - avatar
4 Respuestas
+ 2
0x represents to humans and the compiler that the numbers/letters following after x are in hex notation. You can look up hex if you dont know what that is. But generally its used to represent memory addresses or offsets. Example, int var = 0xA; Is just another way of representing 10 in hex format.
29th Jun 2017, 4:03 AM
aklex
aklex - avatar
+ 1
That's the representation of 0 in hexadecimal number, which start with '0x' (zero then the character x, not "times"), so a 10 in hexadecimal will look like 0xA.
29th Jun 2017, 4:05 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar
+ 1
Is there any practical usage of this? Or is it only for things like that (assigning a value to a variable)? Because in that case, just writing "int var = 10" would be much easier.
29th Jun 2017, 4:10 AM
21kHzBANK21kHZ
21kHzBANK21kHZ - avatar
+ 1
I looked it up a little and hexadecimals seem to represent a lot of things. Like '\x1B is the Esc control character. Can any of this be implemented in C++?
29th Jun 2017, 4:27 AM
21kHzBANK21kHZ
21kHzBANK21kHZ - avatar