Created
October 10, 2018 15:39
-
-
Save benlansdell/39d723b57e49ec9d42c2a8d0368586e6 to your computer and use it in GitHub Desktop.
Basic pointer behavior in C
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
Basic pointer behavior in C |
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> | |
#include <math.h> | |
int main(void) | |
{ | |
float x; | |
int y; | |
float *ptr_x = &x; | |
x = 2; | |
printf("x=%f\n", x); | |
printf("&x=%p\n", &x); | |
printf("*ptr_x=%f\n", *ptr_x); | |
printf("ptr_x=%p\n", ptr_x); | |
printf("&ptr_x=%p\n", &ptr_x); | |
//Can also do assignment through dereference: | |
*ptr_x = 5; | |
printf("*ptr_x = 5; Now *ptr_x=%f\n", *ptr_x); | |
printf("ptr_x=%p\n", ptr_x); | |
printf("&ptr_x=%p\n", &ptr_x); | |
//What is a void pointer? | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment