Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* OUTPUT
- ------
- 0x7ffebdd9a390
- 1
- ------
- 1
- 0x7ffebdd9a29c
- ------
- (nil)
- ------
- 0x7ffebdd9a29c
- 0x7ffebdd9a29c
- ------
- 2
- */
- #include <stdio.h>
- void main(){
- int integerValue = 1; //integerValue is VALUE
- int* integerPointer; //integerPointer is a POINTER
- printf("------\n");
- printf("%p\n", integerPointer); //Outputs address OS allocated for it
- printf("%d\n",*integerPointer); //Outputs whatever in that memory space from before.
- printf("------\n");
- printf("%d\n",integerValue); //1
- printf("%p\n", &integerValue); //The address of where integerValue exists. & means the point$
- integerPointer = NULL;
- printf("------\n");
- printf("%p\n",integerPointer); //0 or NULL basically address to nothing.
- integerPointer = &integerValue; //We can assign integerValue's address to integerPointer
- printf("------\n");
- printf("%p\n", &integerValue); //Now both output the same address in memory
- printf("%p\n",integerPointer); //You can change that memory using either variable.
- *integerPointer = 2; //* means change data at pointer's location
- printf("------\n");
- printf("%d\n",integerValue);//integerValue is now 2 since the memory it uses was changed.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement