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


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

Re: Don't understand sizeof char* array

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: Don't understand sizeof char* array
Date 2011-08-09 21:41 +1200
Message-ID <9acdlmFv2pU5@mid.individual.net> (permalink)
References <925ae74e-7c1e-401e-908e-36a2760f362b@y16g2000yqk.googlegroups.com>

Show all headers | View raw


On 08/ 9/11 09:34 PM, Angus wrote:
> I have this array:
>     char* s[] = {"cat", "cat", "dog", "mouse", "rat"};
>     int sz = sizeof(s);              // 20  why 20???
>
> I would expect sizeof to report 17.  Why is it reporting 20?

On your system, sizeof(char*) = 4 and you have 5 in the array.

-- 
Ian Collins

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


Thread

Don't understand sizeof char* array Angus <anguscomber@gmail.com> - 2011-08-09 02:34 -0700
  Re: Don't understand sizeof char* array Ian Collins <ian-news@hotmail.com> - 2011-08-09 21:41 +1200
  Re: Don't understand sizeof char* array Juha Nieminen <nospam@thanks.invalid> - 2011-08-09 11:30 +0000
  Re: Don't understand sizeof char* array Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-09 08:48 -0400
    Re: Don't understand sizeof char* array gwowen <gwowen@gmail.com> - 2011-08-10 01:23 -0700
      Re: Don't understand sizeof char* array Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-10 09:00 -0400
        Re: Don't understand sizeof char* array Immortal Nephi <Immortal_Nephi@hotmail.com> - 2011-08-10 18:17 -0700
          Re: Don't understand sizeof char* array Paavo Helde <myfirstname@osa.pri.ee> - 2011-08-11 00:30 -0500

csiph-web