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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:29:00+00:00 2026-05-18T20:29:00+00:00

Possible Duplicate: Take the address of a one-past-the-end array element via subscript: legal by

  • 0

Possible Duplicate:
Take the address of a one-past-the-end array element via subscript: legal by the C++ Standard or not?

const int n = ...;
T a[n];
T* begin = &a[0]; //or just a
T* end = begin + n;

I know this is legal and fine. However I am wondering if the following is undefined behavior or is legal as well. Does the answer depend on type T?

T* end = &a[n];

P.S. This question is a curiosity question, so please refrain from mentioning that vector is a better alternative to arrays and the like 🙂

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

    Yes. It is undefined behavior. No, the type of T doesn’t matter.

    The accepted answer in the linked duplicate is in error by its very own selection of standard citations. Unfortunately he muddles logic at the end to come up with exactly the opposite conclusion. The note in 3.9.2/3 is contained within a paragraph that is quite clearly talking about the type, not the ability to dereference. The type of the pointer (array+size) is the same “as-if” there was a valid object of type T there; this does not mean that there IS a valid object there and in fact there isn’t.

    There is a citation in the duplicate of the C99 standard that clearly states that &array[index] will not result in a pointer dereference that is normally implied by array[index]. C99 is not C++ though and I’ve not seen any equivalent text that says the same thing. It is only by that rule that it is legal in C.

    C++0x will contain some of C99, I don’t know if this bit is included. You should not consider them the same language.

    Most C++ compilers will happily eat it up but you could always run into a compliant compiler that does not.

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

Sidebar

Related Questions

Possible Duplicate: Take the address of a one-past-the-end array element via subscript: legal by
Possible Duplicate: Take the address of a one-past-the-end array element via subscript: legal by
Possible Duplicate: Can I call functions that take an array/pointer argument using a std::vector
Possible Duplicate: Take a screenshot via a python script. [Linux] How can I achieve
Possible Duplicate: Design of std::ifstream class Why does (i|o)fstream take a const char* parameter
Possible Duplicate: 'Delegate 'System.Action' does not take 0 arguments.' Is this a C# compiler
Possible Duplicate: PHP take all combinations I'm thinking of making something in PHP that
Possible Duplicate: Backup SQL Schema Only? Anybody tell how to take sql database backup
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How can I take screenshots with Perl? How can I take a

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.