Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #4291

Re: Problem with array objects

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: Problem with array objects
Date 2011-04-24 09:26 +1200
Message-ID <91guh2F6cmU1@mid.individual.net> (permalink)
References (2 earlier) <eg1rp.4730$9h6.2764@newsfe02.ams2> <slrniqrm4f.2usb.aggedor@earl-grey.cloud9.net> <ZuTrp.20047$Vm5.2779@newsfe30.ams2> <slrnir64sj.pso.aggedor@earl-grey.cloud9.net> <%OFsp.42022$bT6.13973@newsfe05.ams2>

Show all headers | View raw


On 04/24/11 07:31 AM, Paul wrote:
>
> "A. Bolmarcich"<aggedor@earl-grey.cloud9.net>  wrote in message
> news:slrnir64sj.pso.aggedor@earl-grey.cloud9.net...
>> On 2011-04-20, Paul<pchristor@yahoo.co.uk>  wrote:
>>>
>>> "A. Bolmarcich"<aggedor@earl-grey.cloud9.net>  wrote in message
>>> news:slrniqrm4f.2usb.aggedor@earl-grey.cloud9.net...
>> [snip]
>>>> A pointer to an array of 4 ints, when dereferenced, returns an array
>>>> of 4 ints.  Look at the output of running the following program.
>>>>
>>>>   #include<iostream>
>>>>   #include<typeinfo>
>>>>
>>>>   int main() {
>>>>     int a1i[4], (*pa1i)[4] =&a1i;
>>>>
>>>>     std::cout<<"typeid(  a1i)="<<typeid(a1i).name()<<std::endl;
>>>>     std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
>>>>   }
>>>>
>>> You are dereferencing an array-type , not an array.
>>> For example:
>>>
>>> int arr[40] ={0};
>>>   int* parr = arr;
>>>   int (*pparr)[40] =&arr;
>>>
>>>   std::cout<<  "address of arr[0]:\t"<<  &arr[0]<<std::endl;
>>>   std::cout<<  "value of *parr:\t\t"<<  *parr<<std::endl;
>>>   std::cout<<  "value of *pparr\t\t"<<  *pparr<<std::endl;
>>>
>>> Dereferencing pparr does not access the array it accesses a temporary
>>> pointer.
>>> The pointer pparr does not reference the array, it references an
>>> array-type
>>> object.
>>
>> Dereferencing pparr accesses an array in the same sense that using
>> the name arr accesses an array.

> No it doesn't

All together now - oh yes it does!

try adding

   (*pparr)[0] = 42;
   std::cout<< "value of  arr[0]\t\t" << arr[0] <<std::endl;
   arr[10] = 1234;
   std::cout<< "value of  (*pparr)[0]\t\t" << (*pparr)[10] <<std::endl;

-- 
Ian Collins

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-04-18 12:44 -0500
  Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-18 21:35 +0100
    Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-04-19 13:46 -0500
      Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-20 17:29 +0100
        Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-04-23 12:59 -0500
          Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-23 20:31 +0100
            Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-04-24 09:26 +1200
              Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-24 00:04 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-04-24 11:24 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-24 02:16 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-04-24 14:10 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-24 04:37 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-04-24 16:11 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-24 13:31 +0100
                Re: Problem with array objects Peter Remmers <p.remmers@expires-2011-04-30.arcornews.de> - 2011-04-24 17:57 +0200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-24 17:39 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-04-25 10:19 +1200
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-04-25 10:12 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-25 00:46 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-04-25 11:59 +1200
                Re: Problem with array objects "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-25 05:01 +0200
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-04-25 14:56 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-25 10:57 +0100
            Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-04-26 12:36 -0500
              Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-26 22:42 +0100
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-04-27 12:53 -0500
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-04-27 19:06 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-27 20:09 +0100
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-04-29 12:57 -0500
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-04-29 19:10 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-04-29 19:56 +0100
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-02 13:20 -0500
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-02 22:43 +0100
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-05 14:13 -0500
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-05 22:21 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-06 10:49 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-06 12:29 +0100

csiph-web