Last active
February 25, 2023 06:55
-
-
Save pavly-gerges/e8bbae849adc46975ae2860b6f8511ec to your computer and use it in GitHub Desktop.
Tests using pointer operations on a data structure to evaluate its members.
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
/** | |
* @brief Tests using pointer operations on a data structure to evaluate its members. | |
* | |
* @author pavl_g | |
*/ | |
#include <stdio.h> | |
struct Test { | |
int x; | |
int y; | |
int z; | |
}; | |
int main() { | |
struct Test test; | |
int* ptr = (int*) &test; | |
*(ptr) = 2; | |
*(ptr+1) = 3; | |
*(ptr+2) = 5; | |
printf("%lld\n", (test.x)); | |
printf("%lld\n", (test.y)); | |
printf("%lld\n", (test.z)); | |
printf("%lld\n", *((int*) &test)); | |
printf("%lld\n", &(test.x)); | |
printf("%lld\n", &(test.y)); | |
printf("%lld\n", &(test.z)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: