hi all
how to find the size of int without using sizof operator
thanks in advance
I think that integers are 4 bytes long
INT_MAX in limits.h gives maximum value of integer
A tricky way, may not be the best way. Here it is:
#include <iostream>
using namespace std;
int main()
{
int a[2] = {1,5};
long addr1 = (long)(&a[0]);
long addr2 = (long)(&a[1]);
cout<<(addr2 - addr1)<<endl;
return 0;
}
take absolute value of addr2-addr1 inorder to avoid a negative answer.
hi all,
How to find size of structure without size off operator..using c
thanks in advance
hi All,
how i get the size of union without sizeof operator usin c
thanks in advance
#include<iostream>
using namespace std;
union test
{
int i;
float j;
double k;
};
int main()
{
test obj1;
cout<<sizeof(obj1)<<endl;
cout<<(int)(&obj1 + 1) - (int)(&obj1)<<endl;
return 0;
}
int i;
cout<<(long)(&i +1) - (long)(&i)