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 6945583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:27:18+00:00 2026-05-27T13:27:18+00:00

I was trying to initialize an array in C and for each element GCC

  • 0

I was trying to initialize an array in C and for each element GCC is generating a mov instruction(which is an inefficient approach if there are many elements to be initialized). How will I load memory with array data and return a pointer from it instead of initializing this way ?

6:array.c       ****         int a[]={1,2,3,4,5,9};
26                      .loc 1 6 0
27 0008 C745E001        movl    $1, -32(%rbp)
27      000000
28 000f C745E402        movl    $2, -28(%rbp)
28      000000
29 0016 C745E803        movl    $3, -24(%rbp)
29      000000
30 001d C745EC04        movl    $4, -20(%rbp)
30      000000
31 0024 C745F005        movl    $5, -16(%rbp)
31      000000
32 002b C745F409        movl    $9, -12(%rbp)
32      000000
  • 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-05-27T13:27:19+00:00Added an answer on May 27, 2026 at 1:27 pm

    I believe the following answers your question “How will I load memory with array data and return a pointer from it instead?”:

    int a_data[] = {1,2,3,4,5,9};
    
    int main() {
      int *a = a_data;
    }
    

    This compiles to:

            .data
    a_data:
            .long   1
            .long   2
            .long   3
            .long   4
            .long   5
            .long   9
    
            .text
    main:
            .cfi_startproc
            pushq   %rbp
            .cfi_def_cfa_offset 16
            movq    %rsp, %rbp
            .cfi_offset 6, -16
            .cfi_def_cfa_register 6
            movq    $a_data, -8(%rbp)
            leave
            ret
            .cfi_endproc
    

    As you can see, the values live on the data segment, and main() simply takes a pointer to the data.

    Of course, if you mutate a[], these mutations will still be there next time you take the address of a_data. If you expect to get the original values, you should be making a copy of a_data, not simply using a pointer to it.

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

Sidebar

Related Questions

I'm trying to initialize the last element in the array int grades[10]; to grade
How do I initialize a 2D array in Perl? I am trying the following
I'm trying to write a simple program in VC++ which will just initialize the
I am trying to initialize the following array of the following struct, but my
I am trying to do something really simple - initialize an array in Javascript.
I'm trying to initialize an array in matlab of ninety zero's. However, I don't
I am declaring an array of void pointers. Each of which points to a
I am trying to initialize an array of objects: SinglyLinkedList offeredClasses[22] = {SinglyLinkedList(CSCE101),SinglyLinkedList(CSCE101L),SinglyLinkedList(CSCE150E),SinglyLinkedList(CSCE150EL),SinglyLinkedList(CSCE150EM),SinglyLinkedList(CSCE150EML),SinglyLinkedList(CSCE155),SinglyLinkedList(CSCE155H),SinglyLinkedList(CSCE156),SinglyLinkedList(CSCE230),SinglyLinkedList(CSCE230L),SinglyLinkedList(CSCE235),SinglyLinkedList(CSCE251),SinglyLinkedList(CSCE310),SinglyLinkedList(CSCE322),SinglyLinkedList(CSCE361),SinglyLinkedList(CSCE351),SinglyLinkedList(CSCE451),SinglyLinkedList(CSCE423),SinglyLinkedList(CSCE428),SinglyLinkedList(CSCE486),SinglyLinkedList(CSCE487)}; but
I am trying to initialize a multidimensional array. Here is my syntax; this does
This is probably the easiest/lamest question. So I am trying to initialize an array

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.