What does the size of a C pointer depend on? Is it the width of the data bus, the width of the address bus, or the word size of the CPU?
I believe it should depend on width of the address bus since a pointer has to address that many locations. Am I right?
(I am looking for a reason for dependency , if any)
The size of a pointer depends on your compiler implementation. In practice it's almost always the native word size of the architecture you're building for.
Notably, the C language standard allows that pointers to different types might have different sizes, the better to support Harvard architectures that have differing sizes of program and data memory, among other things.
It depends on the CPU architecture in question. You can write portable code that takes this into consideration by using intptr_t
(C99 only).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With