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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:06:28+00:00 2026-05-26T07:06:28+00:00

AFAIK sizeof doesn’t evaluate its operands it C++. E.g. int x = 0; sizeof(x

  • 0

AFAIK sizeof doesn’t evaluate its operands it C++.

E.g.

int x = 0;
sizeof(x += 1); // value of x is not changed

But what does this mean?

int arr[5];
sizeof(arr+0); // here array is converted to pointer

Why does the arithmetic on array is applied here?

(§ 5.3.3/4) The lvalue-to-rvalue (4.1), array-to-pointer (4.2), and
function-to-pointer (4.3) standard conversions are not applied to the
operand of sizeof.

  • 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-26T07:06:29+00:00Added an answer on May 26, 2026 at 7:06 am

    The sizeof() operator is calculated at compile time. The expressions are NOT evaluated. It is the type of the expression that is calculated (at compile time) and then used by sizeof().

    So in your first one:

    sizeof( x += 1);
    

    The type of x is int. The result of the += operator is still int. So the sizeof() is still the size of int.

    In this:

    sizeof(arr+0);
    

    Here arr is an array and would have returned the size of the array (if used by itself). But the operator + causes the array to decay into a pointer. The result of the + operator on an array and an integer is a pointer. So here the sizeof() operator will return the sizeof a pointer.

    (§ 5.3.3/4) The lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are not applied to the operand of sizeof.

    This means that:

    std::cout << sizeof(arr);
           // would print sizeof(int)* 5 (because there is no conversion)
           // if sizeof() had behaved like a normal function there
           // would have been a conversion but as you pointed out that
           // does not apply.
    

    But here:

    std::cout << sizeof(arr + 5);
           // prints the sizeof(int*) because the result of the expression
           // is a pointer type (int*)
    

    As a side note:

    This is why

    int x[0];
    int const xSize = sizeof(x)/sizeof(x[0]);
    
    // This works correctly even though x[0] is technically
    // not valid if used in a real expression (but is valid here).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

AFAIK this code is not a valid c++ code by standard: int a =
AFAIK, a thread can not access UI components. But I want to preload images
Why this code allows user do not enter any text? AFAIK + means One
AFAIK, extern keyword should be used for declaration and no value can be associated
AFAIK, for pointers/references static_cast, if a class definition is not visible to compiler at
AFAIK, the rel=nofollow attribute on links instruct search engines not to follow through the
AFAIK, this question applies equally to C and C++ Step 6 of the translation
AFAIK there is no DOS in vista and windows 7, but I need to
AFAIK, all types are derived from System.Object class. Considering this, how can I calculate
AFAIK, there is only one difference: key_id must be int and key_name must be

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.