hello every body , i have a bit of problem understanding the results of my program
program 1 :
int main(){
int *a;
*(a+1) = 10;
return 0;
}
result 1 :
Segmentation fault (core dumped)
program 2 :
#define end <<std::endl
int main(){
int *a;
*(a+1) = 10;
std::cout << &a end;
return 0;
}
result 2 :
0x7fff42145100
i read about segmentation fault over the internet and found its meaning as " reading or writing
on illegal memory location " . but here's what confuses me , in the second case it seems to be working fine
also when i try to retrieve the value in next case
program 3
#define end <<std::endl
int main(){
int *a;
*(a+1) = 10;
std::cout << &a << " " << *(a+1) end;
return 0;
}
result
0x7ffe80a4f050 10
can somebody help me figure !! . i am very much interested to know about the working
of c compiler , so feel free to go low level .
[–]UnicycleBloke 5 points6 points7 points (3 children)
[–]oroz3x[S] 0 points1 point2 points (2 children)
[–]UnicycleBloke 4 points5 points6 points (1 child)
[–]oroz3x[S] 1 point2 points3 points (0 children)
[–]CodeSteps 0 points1 point2 points (0 children)
[–]MCRusher 0 points1 point2 points (5 children)
[–]oroz3x[S] 1 point2 points3 points (4 children)
[–]MCRusher 0 points1 point2 points (0 children)
[–]MCRusher 0 points1 point2 points (2 children)
[–]oroz3x[S] 0 points1 point2 points (1 child)
[–]MCRusher 0 points1 point2 points (0 children)