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

  • Home
  • SEARCH
  • 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 6918379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:51:04+00:00 2026-05-27T09:51:04+00:00

Is the return value of this function well defined by the C standard ?

  • 0

Is the return value of this function well defined by the C standard?

int foo()
{
    char buff[128];
    // This is the important line:
    if ((void*)buff == (void*)(&buff))
        return 1;
    else
        return 0;
}

What is the result of foo? On gcc and clang, it will always be 1, but I do not think that this is guaranteed by the standard.

  • 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-27T09:51:05+00:00Added an answer on May 27, 2026 at 9:51 am

    It will always return 1.

    An array is a contiguously allocated non-empty set of objects with the element type – arrays are not allowed to have padding before or between elements. It follows that a pointer to an array points at the same location as a pointer to the first element, although it has a different type.

    &buff is the address of the variable buff. The variable buff in this case is an array, so &buff is the address of an array – and just like the address of a struct variable is the same location as the address of its first member (although a different type), the address of an array variable is the same location as the address of its first member.

    §6.5.9 tells us:

    6 Two pointers compare equal if and only if both are null pointers,
    both are pointers to the same object (including a pointer to an object
    and a subobject at its beginning)…

    In this case the “pointer to an object” is the pointer to the array, and the “pointer to the subobject at its beginning” is the pointer to the first element of the array.

    In other words, it returns 1 for much the same reason that this code does:

    int foo()
    {
        struct { int a; int b; } s;
    
        return (void*)&s == (void*)&s.a;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Visual C++ is saying my void function needs a return value I compiled this
If I have a function that returns an object, but this return value is
How can I do this in Moq? Foo bar = new Foo(); Fake(bar.PrivateGetter).Return('whatever value')
I've just started to practice with PHP built-in gettype() and its return value. This
How to make this method return boolean value, depending on query return. False -
I am using Datetime.Minvalue which return 1.1.0001. This value can not be stored to
i need to return a JSON with this format: {answers: [{id: 93, value:Ahstron}, {id=94,
Important : Please see this very much related question: Return multiple values in C++
The docs for Dictionary.TryGetValue say: When this method returns, [the value argument] contains the
In python, you can have a function return multiple values. Here's a contrived example:

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.