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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:52:45+00:00 2026-06-07T03:52:45+00:00

I read a question earlier that was closed due to being an exact duplicate

  • 0

I read a question earlier that was closed due to being an exact duplicate of this

When a function has a specific-size array parameter, why is it replaced with a pointer?

and

How to find the 'sizeof' (a pointer pointing to an array)?

but after reading this I am still confused by how sizeof() works. I understand that passing an array as an argument to a function such as

  void foo(int a[5])

will result in the array argument decaying to a pointer. What I did not find in the above 2 question links was a clear answer as to why it is that the sizeof() function itself is exempt from (or at least seemingly exempt from) this pointer decay behaviour. If sizeof() behaved like any other function then

   int a[5] = {1,2,3,4,5};
   cout << sizeof(a) << endl;

then the above should output 4 instead of 20. Have I missed something obvious as this seems to be a contradiction of the decay to pointer behaviour??? Sorry for bringing this up again but I really am having a hard time of understanding why this happens despite having happily used the function for years without really thinking about it.

  • 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-07T03:52:45+00:00Added an answer on June 7, 2026 at 3:52 am

    Because the standard says so (emphasis mine):

    (C99, 6.3.2.1p3) “Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type “array of type” is converted to an expression with type “pointer to type” that points to the initial element of the array object and is not an lvalue.”

    Note that for C++, the standard explicitly says the size is the size of the array:

    (C++11, 5.3.3p2 sizeof) “[…] When applied to an array, the result is the total number of bytes in the array. This implies that the size of an array of n
    elements is n times the size of an element.”

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

Sidebar

Related Questions

I commented earlier on this question (Why java.lang.Object is not abstract?) stating that I'd
Possible Duplicate: Getting exception as “Collection was mutated while being enumerated” This question is
This question is a follow up to an earlier question I had that was
This is a similar question I asked earlier, except different in the fact that
I read a question earlier asking if there was a times method in Python,
I read this question in stackoverflow. The excerpt answer provided by bbum is below:
I read this question but the answer does not perform a refactoring of the
Having read this question Immutable or not immutable? and reading answers to my previous
I have read this question and the simple and clear answer but it's not
I have read this question but it's not quite what I was looking for.

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.