Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing char pointers in C
    primarykey
    data
    text
    <p>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:</p> <pre><code>int characters(char temp[]) { printf("\nAddress of string by &amp;temp: %p",&amp;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 &amp;s: %p",&amp;s); printf("\nAddress of string by s: %p",s); printf("\nContent of string: %s",s); printf("\nAddress of pointer by &amp;t: %p",&amp;t); printf("\nAddress of pointer by t: %p",t); printf("\nContent of pointer: %s",t); getch(); return(0); } </code></pre> <p>The output I get is this:</p> <pre><code>Address of string by &amp;temp: 0x7fff4ab45788 Address of string by temp: 0x7fff4ab457b0 Content of string: Prafulla Shahi Main Address of string by &amp;s: 0x7fff4ab457b0 Address of string by s: 0x7fff4ab457b0 Content of string: Prafulla Shahi Address of pointer by &amp;t: 0x7fff4ab457a8 Address of pointer by t: 0x7fff4ab457b0 Content of pointer: Prafulla Shahi </code></pre> <p>My question is: Whys is the address for the temp array show two different values when asked by &amp;temp and temp?</p> <p>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 &amp;s and s shows the same value.</p> <p>Can anyone please explain this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload