Skip to content

Instantly share code, notes, and snippets.

@gavinwhyte
Created March 16, 2024 20:31
Show Gist options
  • Save gavinwhyte/71aa9ba729dce638ccf576a8b3979c96 to your computer and use it in GitHub Desktop.
Save gavinwhyte/71aa9ba729dce638ccf576a8b3979c96 to your computer and use it in GitHub Desktop.
c pointers
#include <stdio.h>
void function(int param) {
printf("I've received value %d\n", param);
param++;
}
int main(void) {
int variable = 111;
function(variable);
printf("variable %d\m", variable);
return 0;
}
The result is
I've received value 111
variable=111
-------------------------------------------------
#include <stdio.h>
void function2(int *param) {
printf("I've received value %d\n", *param);
(*param)++;
}
int main(void) {
int variable = 111;
function2(&variable);
printf("variable %d\n", variable);
return 0;
}
The result is
I've received value 111
variable=112
@gavinwhyte
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment