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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:06:02+00:00 2026-06-15T02:06:02+00:00

In C++11 when I allocate a dynamic array using T *array = new T[n];

  • 0

In C++11 when I allocate a dynamic array using T *array = new T[n]; it’s already zeroed (using gcc 4.7.2, Ubuntu 12.10 64bit).

  1. Is this forced by the C++11 specification?
  2. How can one allocate an array without zeroing its items? This should be probably a little bit faster.

Edit: I’ve checked that for T = int.

gcc cxx-flags: -std=gnu++11 -O3 -ffast-math -fno-rtti

  • 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-15T02:06:04+00:00Added an answer on June 15, 2026 at 2:06 am

    § 5.3.4

    If the new-initializer is omitted, the object is default-initialized (8.5); if no initialization is performed,
    the object has indeterminate value.

    new-initializer is the () in new T[] (), which you have omitted.

    § 8.5 / 6

    To default-initialize an object of type T means:

    — if T is a (possibly cv-qualified) class type (Clause 9), the default constructor for T is called (and the
    initialization is ill-formed if T has no accessible default constructor);

    — if T is an array type, each element is default-initialized;

    — otherwise, no initialization is performed.

    int[] is default initialized -> each element is default-initialized.

    “Is this forced by the C++11 specification?”: “no initialization is performed”, so no, zeroing is not forced if T has no zeroing constructor (i.e. T is a POD). For T=int, no zeroing has to be performed.

    Why is it zero anyway? If your program allocates new memory from the operating system, the OS zeroes the new memory for you. It would be very dangerous, if you could read memory of another program, which possibly stores sensible data. However, if you write into that memory, free it and allocate some of it again, it should not be zeroed.

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

Sidebar

Related Questions

I am trying to allocate a dynamic string array in the following way and
I don't understand how to Dynamic allocate memory for an array of structs within
I try to dynamically allocate one dimension of a two dimensional array. The array
I need to have a dynamic array, so I need to allocate the necessary
I want to allocate dynamic an array of chars. So i ve the above
Say I have a dynamic array like: int* integers = new int[100]; Is there
I'm trying to allocate dynamic memory to an array of objects, but I keep
It seems to me that delete[] knows the size of a dynamic allocated array.
The objective is to build a infinite tree using dynamic arrays. items[3] - MENUITEM
I followed Jonathan's code from here ( MPI_Bcast a dynamic 2d array ) to

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.