Created
July 26, 2024 19:56
-
-
Save jrelo/833628070d36f0275a9d36c128275424 to your computer and use it in GitHub Desktop.
This file contains 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> | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`#include <stdio.h>
int main() {
int value = 10;
int *ptr = &value; // ptr now holds the address of value
}`