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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -