#include <stdio.h> #define SIZEOF(x) (unsigned int)( (char *)(&x+1)-(char *)(&x) ) int main() { int buf[4]; printf("sizeof %d\n",SIZEOF(buf)); }
it works only for variable not for data type.
declare two pointers.
assign the address of the variable to these two pointers.
increment any one of the pointer.
difference in addresses of these two pointers will be the size of the variable.
Take an array of that datatype, then subtract the address of an element from the address of next element.
#include<stdio.h> main() { int a[5] = {1,2,3,4,5}; Int size; size = &a[2] - &a[1]; printf("size = %d\n",size); }
How can I wwap value two variables without using third variable or +/- operator?
Something like :
IN(Range)