Skip to content

Instantly share code, notes, and snippets.

@jrelo
Created July 26, 2024 19:56
Show Gist options
  • Save jrelo/833628070d36f0275a9d36c128275424 to your computer and use it in GitHub Desktop.
Save jrelo/833628070d36f0275a9d36c128275424 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main() {
int value = 10;
int *pointer = &value;
// print the address of the variable and the pointer value
printf("Address of 'value': %p\n", (void *)&value);
printf("Value of 'pointer': %p\n", (void *)pointer);
// print the value pointed to by the pointer
printf("Value at the address pointed by 'pointer': %d\n", *pointer);
// change the value pointed to by the pointer
*pointer = 20;
printf("New value of 'value' after modification through pointer: %d\n", value);
// pointer arithmetic (incrementing pointer)
pointer++;
printf("Address after incrementing pointer: %p\n", (void *)pointer);
printf("Garbage value at new pointer address: %d\n", *pointer);
return 0;
}
@jrelo
Copy link
Author

jrelo commented Jul 26, 2024

`#include <stdio.h>

int main() {
int value = 10;
int *ptr = &value; // ptr now holds the address of value

printf("Address stored in pointer ptr: %p\n", (void *)ptr);
printf("Value at the address stored in ptr: %d\n", *ptr);
printf("Address of the pointer ptr itself: %p\n", (void *)&ptr);

return 0;

}`

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