5

Who thought this was a good idea

oh well if they couldn't care to initialize the variable I GUESS WE'LL MAKE IT RANDOM

There is probably a reason for it... somewhere

Comments
  • 0
    @Lahsen2016 this example code from SO so no
  • 4
    In standard C a variable definition only gets a pointer to a memory area.

    That area is not prepared in any way and can contain anything the area was used for last.

    Many other languages of later design explicitly either require a initial value or defaults to initializing with some default to prevent leakage from other apps.
  • 1
    @Voxera That only holds for variables on the stack or the heap. For global/static variables the C-standard defines them to start off with every byte set to 0.
  • 0
    @Embeddeded Ok, did not know that ;)

    But I rather be safe and do
    My own initializing anyway ;)
Add Comment