Default values of int when not initialized in c. why do i get different outputs?

后端 未结 5 1874
余生分开走
余生分开走 2021-01-16 13:49

i was just trying to check the default value of int and char when not initialised in c. my problem is that i get two different outputs when i use clrscr() to clear the scree

5条回答
  •  旧巷少年郎
    2021-01-16 14:50

    In managed code, there are default values, usually 0 or equivalent.

    In the unmanaged world, there is no default value. When the memory is allocated, the system just tells you "You can write here is you want, but I don't know what mess the previous program let behind".

    This behaviour is seen for some people as bad since their program can be unpredictable for some obscure reasons, but it is also a way to be able to optimize as much as we can memory management, think of large buffer allocation which when allocated would be filled with 0s, and then filled with actual data. You get twice the performance in unmanaged code!

提交回复
热议问题