Last active
March 14, 2019 10:33
-
-
Save kateolenya/821a4b3d1daa01d39bd49792ffc035e0 to your computer and use it in GitHub Desktop.
Bypassing encapsulation with pointers in C
This file contains 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 "private_var.h" | |
#include <stdio.h> | |
int main() | |
{ | |
struct Contact * Tony; | |
Tony = create_contact(); | |
int * mobile_number_is_here = (int *)Tony; | |
printf("Mobile number: %d\n", *mobile_number_is_here); | |
int * home_number_is_here = mobile_number_is_here + 1; | |
*home_number_is_here = 1; | |
printf("Modified home number: %d\n", *home_number_is_here); | |
delete_contact( Tony ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment