Jump to content

C: Language: Array, Pointers Doubt 03?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
gautham

gautham

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts

{


char ch[6]="Hello";


printf("Initial decleration is: ch[10]=\"Hello\"\n\n");

printf("Address of    &ch=%d\n",&ch);

printf("Address of &ch[0]=%d\n",&ch[0]);


printf("------------\n");


printf("Value in ch where it points to *ch=%d\n",*ch);

printf("Value in ch *(&ch)=%d\n",*(&ch));


}

Output:

Initial declaration is: ch[10]="Hello"

Address of &ch=8832
Address of &ch[0]=8832
------------
Value in ch where it points to *ch=72
Value in ch *(&ch)=8832


-------------------------------------------------------------------------------------
ch[0] ch[1] ch[2] ch[3] ch[4] ch[5]
-------------------------------------------------------------------------------------
H e l l o \0
-------------------------------------------------------------------------------------
8832 8833 8834 8835 8836 8837

-------------------------------------------------------------------------------------
C Language: Scanf and "&" doubt.? - Yahoo! Answers India
-------------------------------------------------------------------------------------

^ considering the above Thread, my question is:

1. where is ch? and address of &ch, are ch and ch[0] both same?

2. how pointer concept is being used here?

3. how come &ch, &ch[0] and value in ch( *(&ch) ) are same?


thank you.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
ch is treated as a pointer to ch[0].
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
gautham

gautham

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
@WingedPanther

ch is treated as a pointer to ch[0].
------------

3. how come &ch, &ch[0] and value in ch( *(&ch) ) are same?


thank you.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users