c++

V

vich

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
 
K

Kira Yamato

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".
 
R

Ron Natalie

vich said:
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?
 
R

Ron Natalie

Kira said:
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.
 
S

Salt_Peter

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-lite/classes-and-objects.html
 
D

Daniel T.

vich said:
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.
 
R

Ron Natalie

Daniel said:
The same size as any other pointer. It's compiler dependent.


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.
 
J

James Kanze

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.
 
J

James Kanze

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,536
Latest member
VeldaYoung

Latest Threads

Top