+ 1
Can we write int* p = 0x61ff08?
I write a program to print the address of a variable using pointers and delete the pointer to cause intentional memory leak, I copy the address that is print on the consol and copy it to the another program like i have written in the question and try to print it on consol but it didn't work as expected. So can we do this in any other way?
3 Réponses
+ 7
When doing
int *p = 0x61ff08
you are trying to put an integer value to a pointer which is not allowed thus will generate an error.
If you really want the pointer to point to that address then you can type cast the address to (int*)
But still you if you try to access that memory location{in order to print it to console in your case}, program will throw a segmentation fault as you are not allowed to do so as that memory location is not allocated to you.
+ 5
Abhishek Dimri pointer just points to a memory location. It doesn't matter what it contains. Just like any other variable is meant to store any value of its data type.
+ 1
Arsenic what if that memory location is NULL?