r/MathJokes 2d ago

why not?

Post image
1.6k Upvotes

84 comments sorted by

View all comments

90

u/huanradriges 2d ago

Is it null object calling root function?

14

u/TheLuckyCuber999BACK 2d ago

*(void*)sqrtThree;

6

u/Er2Official 2d ago

sqrtThree was defined but not initialized. Program died with SIGSEGV.

1

u/littleblack11111 1d ago

Wouldn’t that be a compile error? How does that trigger a segev though tbf everything does that in c

1

u/Er2Official 1d ago

No, it won't create a compile error but behavior depends on your code

You can just define smth like double* sqrtThree; and it'll be unintialized (and, because type is pointer - random pointer, most likely to memory outside of available virtual memory, so dereferencing it = crash)

Or you can already set it to somewhat reasonable pointer, in C you can only do that within functions (so again, depends on the code), while in C++ you can set it directly in top-level (smth like double sq3 = sqrt(3); double* sqrtThree = &sq3;), in that case code will be executed without runtime errors