Skip to content

Instantly share code, notes, and snippets.

@samarthdave
Created April 3, 2024 01:51
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 samarthdave/22cf4e956c3560ac3a7643c786d88558 to your computer and use it in GitHub Desktop.
Save samarthdave/22cf4e956c3560ac3a7643c786d88558 to your computer and use it in GitHub Desktop.
dereference and address of operators shown simply
#include <stdio.h>
void change(int* value) {
*value += 5; // dereference operator
}
int main() {
int a = 5;
printf("a = %d \n", a);
// "&" is the address of operator & yields a pointer
int* b = &a;
change(b);
printf("a = %d \n", a);
change(&a);
printf("a = %d \n", a); // should be 15
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment