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

  • Home
  • SEARCH
  • 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 9275099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:30:32+00:00 2026-06-18T16:30:32+00:00

In C# I could do this: char[] a = new char[] {‘a’, ‘a’, ‘a’};

  • 0

In C# I could do this:

char[] a = new char[] {'a', 'a', 'a'};

But can I do something like that in C++? I tried:

char *a = new char [] {'a', 'a', 'a'};

But it doesn’t compile.

  • 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-18T16:30:33+00:00Added an answer on June 18, 2026 at 4:30 pm

    This is a bug in the C++ spec (which doesn’t let this simple construct to compile). You need to supply the size

    char *a = new char [3] {'a', 'a', 'a'};
    

    See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1469 . Note that if you parenthesize the type name it is a type-id and not a new-type-id and hence syntactically allows you to omit the size expression. So you may be able to find an implementation that allows you to say

    char *a = new (char[]){'a', 'a', 'a'};
    

    Althought it is clear that it wasn’t the explicit intent that this is possible (and some rules in the new paragraphs can be interpreted to forbid it).

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

Sidebar

Related Questions

If I have code that would normally function like this: char* log = new
This could be a very basic Javascript I know but I just can't get
you could say that I am relatively new to C, but I need clarification
I had accidentally tried this, which compiles! So I was wondering what could this
This could save me so much time. Sometimes I find myself writing things like
This could be an amazingly dumb question, but .... I don't think a standard
I think this could be a very easy question for you. But I have
Can anyone help me figure out how I could simplify this code, without using
This may be a stupid question but I can't seem to figure this out.
The code below works for me. How could this work? Wouldn't this segfault? char

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.