Int pointer !!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Int pointer !!!

why we declare pointer as integer and the pointer is string variable ... ? for example : int score = 5; int *pointer; pointer = &score; output 0xbu77io 0xbu77io is not integer ?

4th Jul 2018, 4:27 PM
Mohammad Alshareef
Mohammad Alshareef - avatar
4 Answers
+ 1
Ace This is not my question you didnt understand me ^_^
4th Jul 2018, 4:38 PM
Mohammad Alshareef
Mohammad Alshareef - avatar
+ 1
why that is not mistake to declare pointer as integer ... this as so clear answer it please .... 😚😙😗
4th Jul 2018, 4:52 PM
Mohammad Alshareef
Mohammad Alshareef - avatar
+ 1
Perhaps this will explain: int score = 10; std::cout << &score << "\n"; std::cout << *(&score) << "\n"; int *ptr = &score; std::cout << ptr << "\n"; std::cout << *ptr << "\n"; You a pointer just stores a memory location. A memory location must be dereferenced to access its data. The pointer type tells us _how_ to dereference it: treat it like a char (1 byte), an int (4 bytes), a short (2 bytes) -- 32-bit x86 arch -- and so on. It tells us how to add those N bytes and compute the answer (well, not quite, but let's stick with that analogy).
4th Jul 2018, 6:49 PM
non
0
Ace Thank you pro ^_^
4th Jul 2018, 7:14 PM
Mohammad Alshareef
Mohammad Alshareef - avatar