+ 1

Does *p have an address still now? And what does the error say?

https://code.sololearn.com/czWF4wEffq3b/?ref=app

14th Apr 2021, 2:49 PM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
11 Respuestas
+ 3
At line 10, p == 0, otherwise known as a null pointer. You cannot write to that address and reading from that address caused unexpected results leading to a core dump.
14th Apr 2021, 2:55 PM
Jerry Hobby
Jerry Hobby - avatar
+ 2
Correct. P is null and you can’t use it as a pointer until you point it to somewhere useful.
14th Apr 2021, 3:22 PM
Jerry Hobby
Jerry Hobby - avatar
+ 2
When main() exits, regardless of the return code, memory is freed up.
14th Apr 2021, 3:23 PM
Jerry Hobby
Jerry Hobby - avatar
+ 1
These two programs do not share data. The first one works properly. Then, when it exits, memory is released. The first program exits and released memory whether you use the return command or not.
14th Apr 2021, 3:41 PM
Jerry Hobby
Jerry Hobby - avatar
+ 1
You printed sizeof the pointer x and the sizeof the int that p points to. The pointers size is different than the int size.
14th Apr 2021, 3:44 PM
Jerry Hobby
Jerry Hobby - avatar
0
That means *p has no value now?
14th Apr 2021, 3:06 PM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
0
And yeah does "return 0" clears my RAM after execution of main function?
14th Apr 2021, 3:17 PM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
0
Thanks, Sir
14th Apr 2021, 3:25 PM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
0
https://code.sololearn.com/cgYuqke5mrPm/?ref=app https://code.sololearn.com/cw4wa3LWxdj7/?ref=app Sir, in "(" file I store 8 inside *p.. I tried to cout it in another file "((" But doesn't work though I removed return 0 And what should I call *p?? Pointer or Variable??
14th Apr 2021, 3:30 PM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
0
Another point, in file "(" pointer *p's size is 4 bytes but x's size is 8..how?
14th Apr 2021, 3:40 PM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
0
Roger that
14th Apr 2021, 3:57 PM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar