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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:21:12+00:00 2026-05-14T06:21:12+00:00

I always thought that *&p = p = &*p in C. I tried this

  • 0

I always thought that *&p = p = &*p in C. I tried this code:

 #include <stdio.h>
 #include <stdlib.h>

 char a[] = "programming";
 char *ap = &a[4];  

int main(void)
{

 printf("%x %x %x\n", ap, &*(ap), *&(ap));   /* line 13 */
 printf("%x %x %x\n\n", ap+1, &*(ap+1), *&(ap+1));   /* line 14 */
}

The first printf line (line 13) gives me the addresses:

40b0a8 40b0a8 40b0a8

which are the same as expected. But when I added the second printf line, Borland complains:

“first.c”: E2027 Must take address of a memory location in function main at line 14

I was expecting to get:

40b0a9 40b0a9 40b0a9.

It seems that the expression *&(ap+1) on line 14 is the culprit here. I thought all three pointer expressions on line 14 are equivalent. Why am I thinking wrong?

A second related question: The line

char *ap = a;

points to the first element of array a. I used

char *ap = &a[4];  

to point to the 5th element of array a.

Is the expression

char *ap = a;

same as the expression

char *ap = &a[0];

Is the last expression only more verbose than the previous one?

Thanks a lot…

  • 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-14T06:21:13+00:00Added an answer on May 14, 2026 at 6:21 am

    When you use the C reference operator, it has to point to a valid lvalue, not an arbitrary expression. Thus, &(ap+1) isn’t valid because the value ap+1 is simply an expression, not a location. You can’t say ap+1 = foo();

    And yes, a is the same as &a[0] here. Note that *(a+b) is 100% equivalent to a[b] (see the top answer to Strangest language feature for an unusual example of this equivalence). When getting a pointer to a member of an array, you can use &array[i] or array + i. Example:

    struct foo array[5];
    struct foo *item_3 = &array[3];
    struct foo *also_item_3 = array + 3;
    

    In this case, whether to use array+i or &array[i] is a matter of style. &array[i] is arguably a better choice, as it is clearer that an array item is being gotten. Moreover, &vec[i] works with C++’s vectors, whereas vec+i does not.

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

Sidebar

Related Questions

The comment to this answer got me wondering. I've always thought that C was
I always thought that && operator in Java is used for verifying whether both
I always thought that if you didn't implement a heartbeat, there was no way
I always thought that parentheses improved readability, but in my textbook there is a
I always thought that when you dropped a control onto an .aspx page that
I always thought that internal class has access to all data in its external
I have always thought that the .equals() method in java should be overridden to
I have always thought that the terms internationalization and localization (and their funny abbreviations
I have always thought that in order to connect to SQL server using windows
As as human I always thought that lookup in something sorted is the way

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.