4 ms·
>This depends on the compiler as well as the processor. Yes. On x64 compilers targeting 64bit cpus, the following prints 8 instead of 4: #include <iostream
by jasode 6y ago
>This depends on the compiler as well as the processor.
Yes. On x64 compilers targeting 64bit cpus, the following prints 8 instead of 4:
#include <iostream>
int main () {
std::cout << sizeof(int*) << std::endl;
}
- unwind 6y agoPosting C++ in a thread about C is odd. In C it's: #include <stdio.h> int main(void) { printf("%zu\n", sizeof (int *)); return 0; }
- MaxBarraclough 6y agoThere's a double-quote character missing.
- unwind 6y agoThanks. I suck at posting from my phone. Edited.
- flohofwoe 6y agoThe article talks about the size of the pointee in memory though, not the size of the pointer. An 'int' is usually 4 bytes wide when compiling for 64-bit ISAs (at least I haven't seen situations yet where this isn't the case, my experience is limited to x86 and ARM though). Modern C fixes this ambiguity with sized integer types (e.g. int32_t vs int64_t).
- jasode 6y ago>The article talks about the size of the pointee in memory though, not the size of the pointer. Yes, you're right about the article's text. When I read gp ChrisSD's comment in isolation where he quotes ">A pointer is a memory address" -- followed immediately by him quoting ">On current mainstream Intel processors, _it_ occupies four bytes of memory" ... I thought the "_it_" was referring to a "pointer" instead of plain "int". It didn't occur to me to that the actual article has extra text in between those 2 extracted quotes which drastically changes the assumption of what the pronoun "it" means. My mistake.