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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:21:55+00:00 2026-05-22T20:21:55+00:00

Today I incidentally defined a two dimensional array with the size of one dimension

  • 0

Today I incidentally defined a two dimensional array with the size of one dimension being 0, however my compiler did not complain. I found the following which states that this is legal, at least in the case of gcc:

6.17 Arrays of Length Zero

However, I have two questions on this usage:

First, is this considered as good programming practice? If so, then when should we use it in real world?

Second, the array I defined was two dimensional, with 0 size for one dimension. Is this the same as the one dimensional case? For example,

int s[0]
int s[0][100]
int s[100][0]

Are they all the same in the memory and for the compiler?

EDIT: Reply to Greg: The compiler I am using is gcc 4.4.5. My intention for this problem is not compiler-dependent, however if there are any compiler specific quirks that would be helpful too:)

Thanks in advance!

  • 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-22T20:21:56+00:00Added an answer on May 22, 2026 at 8:21 pm

    In C++ it is illegal to declare an array of zero length. As such it is not normally considered a good practice as you are tying your code to a particular compiler extension. Many uses of dynamically sized arrays are better replaced with a container class such as std::vector.

    ISO/IEC 14882:2003 8.3.4/1:

    If the constant-expression (5.19) is present, it shall be an integral constant expression and its value shall be greater than zero.

    However, you can dynamically allocate an array of zero length with new[].

    ISO/IEC 14882:2003 5.3.4/6:

    The expression in a direct-new-declarator shall have integral or enumeration type (3.9.1) with a non-negative value.

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

Sidebar

Related Questions

Today somebody told me that interface implementation in C# is just Can-Do relationship, not
Today one of our app got rejected due to email button for enquiries and
Today at school the teacher asked us to implement a duplicate-deletion algorithm. It's not
Today I learned that one of the .NET libraries I use, OpenTK, requires me
Today while I was writing some code for two methods that shows and hides
Today I got into a very interesting conversation with a coworker, of which one
Today I noticed that a few Google advertisements in an adsence block on one
today i ran into a possible size limitation of geography type Linestrings within Sql
Today, for no reason, my rails(2.1.0) application is very slow or even not responding.
Today, while I was randomly reading the JavaScript patterns O'Reilly book, I found one

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.