Solve the problem of finding the sizeof an int without using sizeof

  • 2020-04-02 01:03:20
  • OfStack

The code is as follows:


#include <stdio.h>  
int main(int argc, char *argv[])  
{  
    int a[2];  
    unsigned int add1 = &a[0];  
    unsigned int add2 = &a[1];  
    printf("The address of a[0] is %u/n",add1);  
    printf("The address of a[1] is %u/n",add2);  
    printf("The size of int is %u/n", add2 - add1);  
} 

The output is:
The address of a[0] is 3218821936
The address of a[1] is 3218821940
The size of int is 4


Related articles: