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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:17:54+00:00 2026-06-14T10:17:54+00:00

What I was always doing is: int arr[] = {2, 3, 4}; and it

  • 0

What I was always doing is:

int arr[] = {2, 3, 4};

and it always worked.

I’ve heard of a better way to initialize new array, using the pointer:

int *arr = {2, 3, 4};

However, it doesn’t work in any IDE, it throws some errors like int differs in levels of indirection from int, or too many initializers. How should I do this?

  • 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-14T10:17:56+00:00Added an answer on June 14, 2026 at 10:17 am

    That initialization seems to work for me, on gcc, but not correctly.

    int *arr = {2, 3, 4}; //weird behaviour, stores first value `2` as read-only
    
    int arr[] = {2, 3, 4}; //array decl
    

    The former isn’t a correct way to initialize an array.

    For a char*, it makes more sense

    char* arr = "abcde"; //Pointer to a read-only char array in memory
    
    char[] arr = "abcde"; //Normal char array
    

    The difference:

    The former is written to the Rodata (constant, read-only data) section of the assembly, while the latter, resides in the read/write Data-Segment. Any attempt to change the former, might result in a segmentation-fault.


    The places where the values are stored are different.

    char* arr = "abcde";
    arr[1] = 'f'; //(undefined behavior)
    
    char[] arr2 = "abcde";
    arr2[1] = 'f'; //no issue
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always seen on SyncLock examples people using Private Lock1 As New Object '
I'm doing the following and always get green pins: pin.pinColor = MKPinAnnotationColorRed; [self.mapView addAnnotation:pin];
I'm doing some Spring development and I'm trying to decide if libraries should always
I'm interested in doing something like an enum but where the increments aren't always
I always get back Content Length Required 411, what am I doing wrong here?
I'm doing something like this: JFrame frame = new JFrame(); frame.setSize(216, 272); frame.setVisible(true); frame.setLocationRelativeTo(null);
In my android app I'm allocating a large int array. This sometimes gives me
I'm doing an exercise where given an array of N values, I need to
I'm doing lots and lots of inserts of std::pair<int, int> into a std::set ,
I was always using JDBC in JavaSE on single-threaded environment. But now I need

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.