Last active
August 10, 2017 09:39
-
-
Save zhirzh/dec5c1a69dce0bf042b47fba7ae54ab2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void _log(int); | |
void log123() { | |
_log(123); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
short arr[] = {1, 2, 3}; | |
printf("Address of arr - %p\n", &arr); | |
printf("Address of arr[0] - %p\n", &arr[0]); | |
printf("Address of arr[1] - %p\n", &arr[1]); | |
/* | |
| address | size | | |
|---------|------| | |
| arr | 8 | | |
| arr[0] | 4 | | |
| arr[1] | 4 | | |
*/ | |
printf("----\n"); | |
printf("Address of arr[0] - %p\n", &arr[0]); | |
printf("Value of arr[0] - %d\n", *(&arr[0])); | |
printf("----\n"); | |
printf("Address of arr[1] - %p\n", &arr[0] + 1); | |
printf("Value of arr[1] - %d\n", *(&arr[0] + 1)); | |
printf("----\n"); | |
printf("Next memory block - %p - difference with &arr = %d\n", &arr + 1, sizeof(arr)); | |
printf("Real next memory block - %p - difference with &arr = 1\n", (void *)&arr + 1); | |
printf("----\n"); | |
/* | |
When adding an integer `i` to an address of type `T`, say `0xfffffffff000`, | |
the resultant is not `0xfffffffff000 + i`, | |
but rather `0xfffffffff000 + (i * sizeof(T))` | |
*/ | |
printf("Proof 1 - %d\n", (void *)&arr + sizeof(arr) == &arr + 1); | |
printf("Proof 2 - %d\n", (void *)&arr + sizeof(arr[0]) == &arr[0] + 1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment