if I have the following code:
int i = 5;
void * ptr = &i;
printf("%p", ptr);
Will I get the LSB address of i, or the MSB?
Will it act differently between platforms?
Is there a difference here between C and C++?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Consider the size of
intis 4 bytes. Always&iwill gives you the first address of those 4 bytes.If the architecture is little endian, then the lower address will have the LSB like below.
+------+------+------+------+ Address | 1000 | 1001 | 1002 | 1003 | +------+------+------+------+ Value | 5 | 0 | 0 | 0 | +------+------+------+------+If the architecture is big endian, then the lower address will have the MSB like below.
+------+------+------+------+ Address | 1000 | 1001 | 1002 | 1003 | +------+------+------+------+ Value | 0 | 0 | 0 | 5 | +------+------+------+------+So
&iwill give LSB address ofiif little endian or it will give MSB address ofiif big endianIn mixed endian mode also, either little or big endian will be chosen for each task dynamically.
Below logic will tells you the endianess
This behaviour will be same for both
candc++