1. ## finding data sizes

I am trying find the sizes for data types but i am not allowed to use the "sizeof()" method. here is what i need to do, but without the "sizeof()"

cout<<"Size of type char is "
<<sizeof(char);

thank you

2. Must be a homework from a rather odd teacher to solve a rather pointless problem in an unusual way.

What else are you not allowed to use?

Code:
```unsigned char ch = ~0;
int count = 0;
while ( ch != 0 ) { count++ ; ch >>= 1; }```

3. ## What is ~0

Code:
`unsigned char = ~0`
What does the ~0 do ? I had thought that ~ (tilde) was to be used only for destructors.

4. the ~ reverses the bits, so 10001010 tilded would be 01110101.

It's good since it can find the max value of a data type from the min if 00000000 is 0 then tilded it's 11111111 would be the max value, unsigned it would be 255.

5. you could use pointer math...

char *c = 0;
c++;

int * i = 0;
i++;

long *l = 0;
l++;

double *d = 0;
d++;

cout << "sizeof a char is " << (int)c << endl;
cout << "sizeof an int is " << (int)i << endl;
cout << "sizeof a long is " << (int)l << endl;
cout << "sizeof a double is " << (int)d << endl;

aren't I clever?

6. That done be the mostest intelligents answer I've been seen.

7. Heh - two more methods

Code:
```#include <iostream>
#include <cstdlib>
using namespace std;

// difference between adjacent members of an array
#define T1(type) {  \
type d[2];      \
cout << "sizeof(" #type ") is " << (int)&d[1] - (int)&d[0] << endl; \
}

// difference between adjacent members of a struct
// assumes that a struct containing a single type is always packed
#define T2(type) {  \
struct foo { type a; type b; };  \
cout << "sizeof(" #type ") is " << offsetof(foo,b) << endl; \
}

int main ( ) {
T1(char);
T2(char);
T1(short);
T2(short);
T1(int);
T2(int);
T1(double);
T2(double);
return 0;
}```

8. I told you I be smart!

9. Isn't the ~ the bitwise NOT?