#include <stdio.h>
int main(void) {
// Declare an integer and a pointer to it
int num = 5;
int *ptr = #
// Print the value of the integer and the address of the integer
printf("Value of num: %d\n", num);
printf("Address of num: %p\n", &num);
// Print the value of the pointer and the value it points to
printf("Value of ptr: %p\n", ptr);
printf("Value pointed to by ptr: %d\n", *ptr);
// Modify the value of the integer through the pointer
*ptr = 10;
printf("Modified value of num: %d\n", num);
return 0;
}
This program declares an integer called num
and a pointer to it called ptr
. It then prints the value of num
, the address of num
, the value of ptr
, and the value pointed to by ptr
. Finally, it modifies the value of num
through the pointer ptr
and prints the modified value of num
.
Here is an example of the output of this program:
Value of num: 5
Address of num: 0x7ffeea56f7fc
Value of ptr: 0x7ffeea56f7fc
Value pointed to by ptr: 5
Modified value of num: 10
0 Comments