|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
hi
1.what will be the size of character pointer 2. what will be the size of a class which do not have private datamember or member functions? eg. class k{ }; 3. do anybody have any pointers related output questions |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2007-12-26 08:40:45 -0500, vich <sundaram.bhuvana@gmail.com> said:
> hi > 1.what will be the size of character pointer Have you tried to write a sample program to find out? > 2. what will be the size of a class which do not have private > datamember or member functions? > eg. class k{ }; Same question as above. > 3. do anybody have any pointers related output questions Are you preparing for a job interview? Try googling "C++ FAQ". -- -kira |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 2007-12-26 07:40:45 -0600, vich <sundaram.bhuvana@gmail.com> said:
> hi > 1.what will be the size of character pointer Implementation defined. > 2. what will be the size of a class which do not have private > datamember or member functions? > eg. class k{ }; Implementation defined. > 3. do anybody have any pointers related output questions Not me. -dr |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
vich wrote:
> hi > 1.what will be the size of character pointer sizeof (char*) > 2. what will be the size of a class which do not have private > datamember or member functions? public/private/protected has NO real bearing on size. > eg. class k{ }; sizeof(k) is at least one. All objects are at least 1 byte long. It could be bigger. It depends on your implementation. > 3. do anybody have any pointers related output questions Could you rephrase that in English? |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Kira Yamato wrote:
> On 2007-12-26 08:40:45 -0500, vich <sundaram.bhuvana@gmail.com> said: > >> hi >> 1.what will be the size of character pointer > > Have you tried to write a sample program to find out? That would tell him for his specific implementation, but it doesn't give the real answer. > |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Dec 26, 8:40 am, vich <sundaram.bhuv...@gmail.com> wrote:
> hi > 1.what will be the size of character pointer Depends on the machine. However, nobody cares. Code should be transparent to the platform / architecture involved (8 bit, 32 bit, 64 bit, etc) > 2. what will be the size of a class which do not have private > datamember or member functions? A class has no size. Its just a blueprint. > eg. class k{ }; > 3. do anybody have any pointers related output questions try the faq: http://www.parashift.com/c++-faq-lit...d-objects.html |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
vich <sundaram.bhuvana@gmail.com> wrote:
> 1.what will be the size of character pointer The same size as any other pointer. It's compiler dependent. > 2. what will be the size of a class which do not have private > datamember or member functions? > eg. class k{ }; This is a special case. class k { }; class y : k { }; 'sizeof( k )' probably equals 1, which implies that all 'k' objects are one byte, however 'sizeof( y )' probably also equals 1, so class 'k' isn't adding anything to the size of derived objects... So the answer to this question is that it is compiler and situation dependent. > 3. do anybody have any pointers related output questions I don't understand the question. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Daniel T. wrote:
> vich <sundaram.bhuvana@gmail.com> wrote: > >> 1.what will be the size of character pointer > > The same size as any other pointer. It's compiler dependent. > >> 2. what will be the size of a class which do not have private >> datamember or member functions? >> eg. class k{ }; > > This is a special case. > > class k { }; > class y : k { }; > > 'sizeof( k )' probably equals 1, which implies that all 'k' objects are > one byte, however 'sizeof( y )' probably also equals 1, so class 'k' > isn't adding anything to the size of derived objects... > > So the answer to this question is that it is compiler and situation > dependent. > The fact that sizeof(y) is also 1 doesn't change the fact that sizeof(k) is one. It just goes to show that the size of a class is not necessarily the sum of the sizes of it's subobjects. |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On Dec 26 2007, 4:02 pm, Ron Natalie <r...@spamcop.net> wrote:
> vich wrote: > > 2. what will be the size of a class which do not have private > > datamember or member functions? > public/private/protected has NO real bearing on size. Unless the implementation decides otherwise. I don't know of any which do, but I could very easily imagine an implementation where: class C1 { public: double d1 ; char c1 ; double d2 ; char c2 ; } ; class C2 { public: double d1 ; private: char c1 ; public: double d2 ; private: char c2 ; } ; and sizeof( C1 ) == 32 but sizeof( C2 ) == 24. An implementation is allowed to rearrange the order of variables if there is an intervening access specifier. -- James Kanze (GABI Software) email:james.kanze@gmail.com Conseils en informatique orientée objet/ Beratung in objektorientierter Datenverarbeitung 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
On Dec 26 2007, 4:56 pm, "Daniel T." <danie...@earthlink.net> wrote:
> vich <sundaram.bhuv...@gmail.com> wrote: > > 1.what will be the size of character pointer > The same size as any other pointer. It's compiler dependent. It's implementation dependent, but all pointers aren't necessarily the same size. I've used machines where char* (and void*, if void had existed back then) was larger than int*, and on one of the most wide spread machines some years ago, function pointers could have a different size than data pointers. (Back when I last worked on a portable compiler, we considered four different sizes for pointers: char pointers, other data pointers, function pointers and label pointers---you can't declare anything with the last type in C/C++, but they were used by Fortran, and internally in the code generated for a switch.) -- James Kanze (GABI Software) email:james.kanze@gmail.com Conseils en informatique orientée objet/ Beratung in objektorientierter Datenverarbeitung 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 |
|
![]() |
| Outils de la discussion | |
|
|