Thanks for the reply, I know about the multiples of 4, because if you take the code below here, the sizeof(address) should give 22 and gives 24 as result. It's written that if you want to minimize wasted space you should simply order the members(from large to small). I tried this in the below written code but to no avail, sizeof(address) still remains 24.
Pointer of type void can point to any type of data if thats what you asking while int type pointers point only to int data and char type pointers point to char type data.
That is not true. You can make char* point to int* and vice versa. That happens frequently, especially in database and socket programming.
Here is an example:
int x = 123;
// now buf contains the binary representation of the integer
// convert back to int
int y = *(int*)buf;
>>But, so how can I find out what my restrictions are to pointer types char*, int*, and void* ?
There are none that applies to one type of pointer an not to the other types. typecasting may be necessary to convert one type of pointer to another, as shown in the above example.
Alignment does NOT change the size of a structure, only the address where the object is located. Packing will change the size of the structure by either adding or removing holes. If you want to remove all holes from the structure pack the structure on 1 byte alignment as in the example below. Change the value of the pack and you will get different structure size.
long int number;
That is not true. You can make char* point to int* and vice versa.
I said you can't make a int* point to char data and not char pointer.
Of couse when dealing with commands like memcpy which deal in raw bits, you can use any type of pointer, it doesnt bother -- all it does is copy the bit representation from the source location to the destinatino location.
What I meant was you cant do something like:
int* ptr_int = 0 ;
char* ptr_char = 0 ;
char ch = '\0' ;
int i = 0 ;
ptr_int = & i ; // ok
ptr_char = &ch; // ok
ptr_int = &ch ; //error
ptr_char = &i ; // error
Of couse you can make it go away with typecasting but thats a different story altogether.