Why do C and C++ compilers place explicitly initialized and default initialized global variables in different segments?

Neither language C or C++ has any notion of “segments”, and not all OSs do either, so your question is inevitably dependent on the platform and compiler.

That said, common implementations will treat initialized vs. uninitialized variables differently. The main difference is that uninitialized (or default 0-initialized) data does not have to be actually saved with the compiled module, but only declared/reserved for later use at run time. In practical “segment” terms, initialized data is saved to disk as part of the binary, while uninitialized data is not, instead it’s allocated at startup to satisfy the declared “reservations”.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)