Passing char pointers in C

Viewed 3560

I am learning pointers in C, so I did this to check out the output I should hope when I do something. Here it is:

int characters(char temp[])
{
    printf("\nAddress of string by &temp: %p",&temp);
    printf("\nAddress of string by temp: %p",temp);
    printf("\nContent of string: %s",temp);     
    return 0;
}
int main()
{
    char s[] = "Prafulla Shahi";
    char *t=s;
    clrscr();
    characters(t);
    printf("\nMain\nAddress of string by &s: %p",&s);
    printf("\nAddress of string by s: %p",s);
    printf("\nContent of string: %s",s);
    printf("\nAddress of pointer by &t: %p",&t);
    printf("\nAddress of pointer by t: %p",t);
    printf("\nContent of pointer: %s",t);
    getch();
    return(0);
}

The output I get is this:

Address of string by &temp: 0x7fff4ab45788
Address of string by temp: 0x7fff4ab457b0
Content of string: Prafulla Shahi    
Main
Address of string by &s: 0x7fff4ab457b0
Address of string by s: 0x7fff4ab457b0
Content of string: Prafulla Shahi
Address of pointer by &t: 0x7fff4ab457a8
Address of pointer by t: 0x7fff4ab457b0
Content of pointer: Prafulla Shahi

My question is: Whys is the address for the temp array show two different values when asked by &temp and temp?

My understanding is, temp is an array variable, but it has its own address (similar behavior to the pointer t. Why does it not behave like the usual variable array s?). The array s[] in main() is an array too, but its address when called by &s and s shows the same value.

Can anyone please explain this?

5 Answers
Related