If i have an array that i know is in address 0x40001008, given the below code what are the values of arrayptr and x?
unsigned short array[5] = {0x123, 0x456, 0x789, 0xabc, 0xdef};
unsigned char *arrayptr = (unsigned char *)array +3;
unsigned short x = *arrayptr;
Base address of the array called array is 0x40001008 or 40001008H given in Hexadecimal number system.
1.) arrayptr is a character pointer which is assigned the value = (unsigned char *)array + 3 , the array pointer is typecasted into a character pointer i.e. (unsigned char *)array and adding 3 to it will increase it by 3 byte as char occupies 3 byte so the value of arrayptr = 0x4000100B using the calculation given below.
0x40001008 | |
+ | 3 |
Ans | 0x4000100B |
since 8+3 = 11 in decimal system and 11 = B in hexadecimal system.
2.) x is assigned the value at adress location 0x4000100B and at the address 0x4000100A the value 0x456 is present i.e. (0100 0101 0110) in binary and (1110) in decimal , so the value of x is 4.
Get Answers For Free
Most questions answered within 1 hours.