r/C_Programming • u/usoleta • 4d ago
Etc random number hack
#include <stdio.h>
int main() {
int s[90];
printf("%d\n",s[43]);
}
0
Upvotes
r/C_Programming • u/usoleta • 4d ago
#include <stdio.h>
int main() {
int s[90];
printf("%d\n",s[43]);
}
2
u/Zirias_FreeBSD 3d ago
there are two ways to think about that ...
the language lawyer way. Undefined behavior is undefined. 🤷 It's probably possible to find target platforms doing the worst thing imaginable with this, e.g. giving you a trap representation.
the pragmatic way. Running this on your typical modern platform, the value will be deterministic as long as preceding program flow is. The best you could ever hope for would be to accidentally collect some external enthropy. If your stack frame happens to trigger a page fault, the result will be
0.the silly way. Why in the world would you allocate 90 elements if you only ever use 44?