Skip to content

Instantly share code, notes, and snippets.

@benlansdell
Created October 10, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benlansdell/39d723b57e49ec9d42c2a8d0368586e6 to your computer and use it in GitHub Desktop.
Save benlansdell/39d723b57e49ec9d42c2a8d0368586e6 to your computer and use it in GitHub Desktop.
Basic pointer behavior in C
Basic pointer behavior in C
#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