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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:28:06+00:00 2026-06-04T20:28:06+00:00

Possible Duplicate: May I treat a 2D array as a contiguous 1D array? Consider

  • 0

Possible Duplicate:
May I treat a 2D array as a contiguous 1D array?

Consider the following code:

int array2d[10][10];
int *array1d = array2d[0];

I never heard of an implementation where it wouldn’t work, but is it legal to access and manipulate array2d via array1d? Which section of the standard allows this? Is there anything in the standard preventing implementations from inserting extra space or padding between each of the second level arrays (not that its needed, but still)?

Bonus question: Is there a way to access array2d as an int[100] which does not require a reinterpret_cast or a C-style one?

  • 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-04T20:28:08+00:00Added an answer on June 4, 2026 at 8:28 pm

    If memory serves, the standard gives this as an example of something that’s officially undefined behavior, but essentially always works. [Edit: Here’s what I was thinking of: C99, §J.2 (Undefined behavior):

    • An array subscript is out of range, even if an object is apparently accessible with the
      given subscript (as in the lvalue expression a[1][7] given the declaration int
      a[4][5])

    I’m not entirely certain that applies though, as you’re getting the address of the beginning of an array and converting it to a simple pointer to the underlying type.]

    Arrays are required to be contiguous, so it cannot insert any padding between elements of an array. That’s true whether you have an array of int or an array of arrays.

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

Sidebar

Related Questions

Possible Duplicate: Search and replace inside an associative array I think this may have
Possible Duplicate: performSelector may cause a leak because its selector is unknown I did
Possible Duplicate: Pure virtual functions may not have an inline definition. Why? I've come
Possible Duplicate: Emacs code to automatically set indent-tabs-mode according to existing code When I'm
Possible Duplicate: C++ variable types limits I have a defined type that may not
Possible Duplicate: Collection was modified; enumeration operation may not execute HI there, I am
Possible Duplicate: C dynamically growing array I have a program and I need to
Possible Duplicate: casting unused return values to void I read some source code, and
Possible Duplicate: How may I reference the script tag that loaded the currently-executing script?
Possible Duplicate: How may I reference the script tag that loaded the currently-executing script?

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.