size of pointers

Below is perhaps the simplest program that will determine the size of a pointer (in bytes). It can give an insight into whether the underlying Operating System and/or architecture is 32- or 64-bit.

int main() {
    return( sizeof( int* ) );
}

The return value can be queried from the shell with an echo $?.

The return value is typically a 4 for a 32-bit Linux distribution, or an 8 for a 64-bit distribution.

A slightly fancier version of the above program could be

#include 
int main() {
    printf( "ptr size: %zu\n", sizeof( int *) );
    return 0;
}

Notes:

  • the type of the result of the sizeof operator is size_t.
  • The proper printf conversion specification is %zu
    • the z length modifier indicates a size_t argument
    • the u conversion specifier converts the unsigned int argument to decimal