+ 1

I dont understand what is going on here and how output is coming 4500?

int main() { int *p; p=(int*)4500; printf("%d",p); return 0; }

1st Aug 2019, 8:10 AM
parag sahu
parag sahu - avatar
4 Answers
+ 2
Got u bro ~ swim ~ . One more thing int main() { int a=10; char *p; p=(char*)&a; return 0; } This is also very confusing.
1st Aug 2019, 9:03 AM
parag sahu
parag sahu - avatar
+ 1
So ~ swim ~ u mean that (int*) is the main player here? It is converting 4500 explicitly into address ?
1st Aug 2019, 8:30 AM
parag sahu
parag sahu - avatar
0
~ swim ~ actually I did not understand that what is happening inside memory or to the address when (char*)&a thus conversion is taking place.
1st Aug 2019, 9:25 AM
parag sahu
parag sahu - avatar
0
I got u ~ swim ~ but by doing this (char*)&a . Now how it is dereferencing the data in variable a completely. Since the data type of pointer decides how much data will be dereferenced. When we have this int a=10; char *p; p=&a; I got your explanation that why data in a can't be dereferenced completely . But when we write p=(char*)&a; Then what happens ? Now how that data is dereferencing completely.
1st Aug 2019, 10:32 AM
parag sahu
parag sahu - avatar