Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8702221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:35:56+00:00 2026-06-13T02:35:56+00:00

Hello Please consider the code snippets below compiled with gcc on a Linux machine(64bit)

  • 0

Hello Please consider the code snippets below compiled with gcc on a Linux machine(64bit) with the corresponding memory map

#include <stdio.h>

int global = 2;

int main(void)
{
    int local = 0;

    return 0;
}

text       data     bss     dec     hex filename

1092        500      16    1608     648 mem

Here since there is a global variable initialized to 2 . Its been stored in the data segment
Consider the case of making it const as shown below

#include <stdio.h>

int const global = 2;

int main(void)
{
    int local = 0;

    return 0;
}

text       data     bss     dec     hex filename
1096        496      16    1608     648 mem

Here the global variable is moved from the data segment to the text segment.

Why is it moved from the data to the text segment ?

Since the data segment is divided into read and read-write areas It should have been stored in the read area of the data right ?

What happens to a uninitialized global variable initialized in the middle of the code ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:35:59+00:00Added an answer on June 13, 2026 at 2:35 am

    On a modern system, the constant is in a section of the object file reserved for read-only data. That section gets lumped together with the “text” (program code) section by the size command in its default mode, but you can make it give you more detail:

    $ size test.o  # compiled from the code in the question
       text    data     bss     dec     hex filename
         58       0       0      58      3a test.o
    
    $ size -A test.o
    test.o  :
    section           size   addr
    .text                6      0
    .data                0      0
    .bss                 0      0
    .rodata              4      0
    .comment            29      0
    .note.GNU-stack      0      0
    .eh_frame           48      0
    Total               87
    

    See how the “text” number produced by the first command is the sum of the .text, .rodata, and .eh_frame numbers produced by the second question?

    You can tell that the constant is in .rodata and not .text with the objdump command:

    $ objdump -t test.o | grep -w global
    0000000000000000 g     O .rodata    0000000000000004 global
    

    (The ‘g’ is for global, and the ‘O’ is for ‘Object’ as opposed to ‘F’ for Function.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please explain the code below: @title(text: String) = @{ text.split(' ').map(_.capitalize).mkString( ) } <h1>@title(hello
Please see code below: <div style=background:#F00;width:800px;> <div style=float:left> Hello Hello Hello Hello Hello Hello
hello Friends please verify my code Is it a right way to pass optional
Please consider the three functions. std::string get_a_string() { return hello; } std::string get_a_string1() {
Hello everyone please guide whats wrong with this code that image is not visible
Can you please explain why 'hello world' isn't returned below? What do I need
Hello please help to translate the next line of basic code to Delphi for
Hello everyone please help me out regarding this this piece of code $user =
Hello people I need help please. Here's my code. In here is a list
Hello friends I have tried many times but I am not successful than please

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.