uninitialized data segment of program memory -


in uninitialized data segment, kernel initialize uninitialized variable 0.

but if directly use uninitialized variable (for eg. int sum; , not int sum=0; ) , use in program sum=sum+n(n number), sum take garbage value.

so why sum take garbage value if has been initialized 0 kernel?

you seem asking difference between compile-time initialization , run-time initialization. in following c code:

int i; int main() {     int j;     return + j; } 

i globally scoped variable , default initialized zero, achieved including in data segment of program. either written block of initial values binary or describe loader size of block , loader flood-fill zeros when executable starts.

j, however, local variable live in registers or on stack. c , c++ choose not default initialize these values, , if access them without initializing them, see value happens in register/stack location.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -