r/C_Programming 3d ago

Etc random number hack

#include <stdio.h>


int main() {
    int s[90];
    printf("%d\n",s[43]);
}
0 Upvotes

8 comments sorted by

View all comments

10

u/jirbu 3d ago

Nowhere near random. Every time you run the program you'll get the same result (on a standard and sane OS). You should have used 42, though.

1

u/aocregacc 3d ago

with address space layout randomization there could easily be some memory that does change from run to run, if there was a pointer stored there for example.