What is the size of void? What is the size of void? c c

What is the size of void?


The type void has no size; that would be a compilation error. For the same reason you can't do something like:

void n;

EDIT.To my surprise, doing sizeof(void) actually does compile in GNU C:

$ echo 'int main() { printf("%d", sizeof(void)); }' | gcc -xc -w - && ./a.out 1

However, in C++ it does not:

$ echo 'int main() { printf("%d", sizeof(void)); }' | gcc -xc++ -w - && ./a.out <stdin>: In function 'int main()':<stdin>:1: error: invalid application of 'sizeof' to a void type<stdin>:1: error: 'printf' was not declared in this scope


If you are using GCC and you are not using compilation flags that remove compiler specific extensions, then sizeof(void) is 1. GCC has a nonstandard extension that does that.

In general, void is a incomplete type, and you cannot use sizeof for incomplete types.


Although void may stand in place for a type, it cannot actually hold a value. Therefore, it has no size in memory. Getting the size of a void isn’t defined.

A void pointer is simply a language construct meaning a pointer to untyped memory.