What's the size of a pointer in C in a 32-bit machine using a 32-bit Compiler?
What's the size of a pointer in C in a 64-bit machine using a 32-bit compiler?
Asked
Active
Viewed 602 times
-15

NAVEEN
- 111
- 1
- 1
- 5
-
2`printf ("%d\n", sizeof (void*)) ;` – TonyK Mar 03 '15 at 08:13
-
1This might help: [What the pointer size in 64 bits computer in C++?](http://stackoverflow.com/questions/6841405/what-the-pointer-size-in-64-bits-computer-in-c) – Emil Laine Mar 03 '15 at 08:14
-
@Ben Zotto There are many amateurs to downvote questions.:) Usually they have nothing to answer a question.:) – Vlad from Moscow Mar 03 '15 at 08:14
-
9Honestly, the OP does not demonstrate any effort to solve the questions on his own. Usually it is expected to introduce the problem in a clear and concise manner (check), and highlight the difficulties that have prevented from solving the problem himself (not check). – moooeeeep Mar 03 '15 at 08:19
-
@Daniel Kleinstein At least I do not see any substantial answer. – Vlad from Moscow Mar 03 '15 at 08:22
-
It's not possible to give direct answer your question as it is. Please name the platform and compiler, as it will be relevant to the answer. – user694733 Mar 03 '15 at 08:24
-
@VladfromMoscow If you are unhappy with the answers, then please provide one yourself. – trojanfoe Mar 03 '15 at 08:30
-
@trojanfoe I am unhappy with downvotes of the question. Reread my first comment. You should redirect your comment to whose who downvoted the question. They have nothing to say except off-topic comments. – Vlad from Moscow Mar 03 '15 at 08:33
-
@VladfromMoscow I was referring to your comment "At least I do not see any substantial answer". – trojanfoe Mar 03 '15 at 08:33
-
@trojanfoe I have not downvoted the question opposite to others. – Vlad from Moscow Mar 03 '15 at 08:36
1 Answers
6
The machine is not relevant, provided a 64-bit Operating system is capable of runnning 32-bit apps (most are); it depends on the type of executable you create (-m32
etc.).
You can answer this yourself by compiling and running the following code:
#include <stdio.h>
int main(int argc, const char **argv)
{
printf("Pointer size is %u bytes\n", (unsigned)sizeof(void *));
return 0;
}
The answer will be 4 (32-bits).

trojanfoe
- 120,358
- 21
- 212
- 242
-
-
1@NAVEEN It depends on whether you tell the compiler to create a 32- or 64-bit executable. The GNU compiler, for example, uses `-m32` or `-m64` to define the type. `clang` under OSX uses `-arch x86` or `-arch x86_64` and the Microsoft compiler uses `/MACHINE:X86` and `/MACHINE:X64`. – trojanfoe Mar 03 '15 at 08:19
-
1@trojanfoe This does not answer the question. It only advices how to check the size of pointer in some particular implementation. – Vlad from Moscow Mar 03 '15 at 08:19
-
@VladfromMoscow Please note the "The answer will be 4 (32-bits)." at the end. – trojanfoe Mar 03 '15 at 08:20
-
@trojanfoe That is a guess really. Correct answer would have been *"It's implementation defined"*. – user694733 Mar 03 '15 at 08:21
-
@user694733 He can check for himself and I have shown him how. Can you tell me of any 32-bit systems that would not return `4` as the answer? – trojanfoe Mar 03 '15 at 08:22
-
2@user694733: No, trojanfoe answered correctly. Re-read the question carefully. He's asking two very specific questions. Both questions boil down to the last bit, which states "using 32-bit compiler" and hence, the answer will be 32 bits. – Edward L. Mar 03 '15 at 08:24
-
Pointer size does't depends on any under lying architecture. It would be given as option during compilation. But recommended to use -M64 for 64 bit machine so it can access beyond 4GB. – NAVEEN Mar 03 '15 at 08:34
-
-
If it 32 bit OS on 64 bit machine, all binaries should be compiled with -m32 bit option. So pointer size is 32 bit. – NAVEEN Mar 03 '15 at 08:38
-
@trojanfoe Is there a particular reason why you cast the result of sizeof to unsigned instead of doing `printf("Pointer size is %zu bytes\n", sizeof(void *));`? – RobertS supports Monica Cellio Apr 04 '20 at 07:30
-
1@RobertSsupportsMonicaCellio Because I didn't know about the `%zu` format specifier :) – trojanfoe Apr 04 '20 at 08:18