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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:49:11+00:00 2026-05-29T03:49:11+00:00

I tried some code to check the behavior of array and pointers. Its as

  • 0

I tried some code to check the behavior of array and pointers. Its as follows.

#include <stdio.h>
main(){
int s[]={1,2};
int *b=s;
printf("%d, %d, %d\n", s, &s, *s);
printf("%d, %d, %d\n", b ,&b, *b);
}

Initially I thought of pointers and array to be same BUT…
To my surprise the value of ‘s’ and ‘&s’ are SAME unlike ‘b’. Does that mean an Array variable “points to itself?”

I am also now confused with what actually is a variable “name”? How its binding takes place with a location in memory? I am just unable to visualize things that go on there!
And where in memory (RAM) is all the information stored at run time?

  • 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-29T03:49:12+00:00Added an answer on May 29, 2026 at 3:49 am

    Except when it is the operand of the sizeof or unary & operators, or is a string literal being used to initialize another array in a declaration, an expression of type “N-element array of T” will be replaced with an expression of type “pointer to T“, and the value of the expression will be the address of the first element in the array.

    Assume the following code:

    int arr[10];
    foo(arr);
    

    In the call to the function foo, the expression arr is converted from type “10-element array of int” to “pointer to int“, and the address of the first element of arr is what actually gets passed to foo.

    We would define foo as either

    void foo(int a[]) {}
    

    or

    void foo(int *a) {}
    

    In the context of a function parameter declaration, T a[] and T a[N] are identical to T *a; the parameter is a pointer type, not an array type. Note that this is only true for function parameter declarations.

    As mentioned above, one exception to this rule is when the array expression is the operand of the unary & operator. If we change the call to foo to read

    foo(&arr);
    

    then the type of the expression &arr is “pointer to 10-element array of int“, or int (*)[10], and the value of the expression is the address of a. For this, the definition of foo would be

    void foo(int (*a)[10]) {}
    

    In C, the address of the array and the address of the first element of the array are the same – thus both of the expressions arr and &arr have the same value, but their types are different. This matters for operations involving pointer arithmetic. For example, assume our code had been written

    int arr[10];
    foo(arr);
    ...
    void foo(int *a)
    {
       ...
       a++;  
       ...
    }
    

    On entry, a points to arr[0]. The expression a++ would advance the pointer to point to the next integer in the array (arr[1]).

    Now assume the code had been written as

    int arr[10];
    foo(&arr);
    ...
    void foo(int (*a)[10])
    {
      ...
      a++;
      ...
    }
    

    On entry, a still points to arr[0] (remember, the address of the array is the same as the address of the first element of the array), but this time the expression a++ will advance the pointer to point to the next 10-element array of integers; instead of advancing the pointer sizeof (int) bytes, we advance it sizeof (int[10]) bytes.

    So this is why in your printf statement you see the same values for both s and &s. You should use the %p conversion specifier to print pointer values, and it expects the corresponding argument to be type void *, so change those printf statements to

    printf("%p %p %d\n", (void *) s, (void *) &s, *s);
    printf("%p %p %d\n", (void *) b, (void *) &b, *b);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen some code such as: out.println(print something); I tried import java.lang.System; but it's
I was trying to speed up some code, and then I tried compiling a
Recently I tried to explain some poorly designed code to my project manager. All
I'm compiling some code that relies on include guards to prevent multiple definitions of
I was trying to write some code that would check if an item has
I tried some code in Application_Error like this Session[mysession] = Some message; but the
I try to draw some lines with different colors. This code tries to draw
I tried some add to favorties JavaScript scripts.. With IE8, I get an access
Just tried some small graphics application of mine on Windows 7, and I'm getting
I've looked for some other articles on this problem and even tried some of

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.