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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:56:25+00:00 2026-05-28T06:56:25+00:00

Why is int *a = new int[10]; written as int *a; a = new

  • 0

Why is

int *a = new int[10];

written as

int *a;
a = new int[10];

instead of

int *a;
*a = new int[10];

?

The way I see it, in the second block of code you’re saying a, which was a pointer variable, is now an array. In the third block of code you’re saying the thing a points to is now an array. Why does the second make more sense than the third?

  • 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-28T06:56:26+00:00Added an answer on May 28, 2026 at 6:56 am

    new int[10] returns a pointer to the first element in the array (which is of type int*). It does not return a pointer to the array (which would be of type int(*)[10]).

    a = new int[10] means make a point to the first element of the dynamically allocated array. *a is not a pointer at all. It is the object pointed to by the pointer a (which is of type int).


    Note that if you actually had a named array object, the syntax would still be the same:

    int x[10];
    int* a = x;
    

    Why? In C++, in most cases, whenever you use an array, it is implicitly converted to a pointer to its initial element. So here, int* a = x is the same as int* a = &x[0];.

    (There are several cases where the array-to-pointer decay does not occur, most notably when the array is the operand of the & or sizeof operators; they allow you to get the address of the array and the size of the array, respectively.)

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

Sidebar

Related Questions

Code snippet (normal pointer) int *pi = new int; int i = 90; pi
suppose I declare a dynamic array like int *dynArray = new int [1]; which
Having code: int** a = new int*[2]; a[0] = new int(1); a[1] = new
I have an array of integers: int[] number = new int[] { 2,3,6,7 };
Having code: struct B { int* a; B(int value):a(new int(value)) { } B():a(nullptr){} B(const
I'm quite new to programming larger applications. I have now written a command line
I've written some code that should make a new image. My background image has
int[] arrc = new int[] {1, 2, 3}; System.out.println(new ArrayList(Arrays.asList(arrc))); prints address, but i
Say I have two lists: var list1 = new int[] {1, 2, 3}; var
Given a list of elements like so: int[] ia = new int[] { -4,

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.