On-Line C++ Programming Tests

S

Steve Fox

I have been doing C++ for 13 years and was asked to take an online-C++
programming test.

WHAT A JOKE!!!

It's frustrating taking a test by someone who obviously knows less than you
do....and doesn't know enough to write such a test.

e.g.

Question 10:

What is the size in bytes allocated for objects of the type SomeClass?


class SomeClass
{
public:
int x ;
int y ;
} ;
 
M

Mike Wahler

Steve Fox said:
I have been doing C++ for 13 years and was asked to take an online-C++
programming test.

WHAT A JOKE!!!

Most online C++ 'tests' are.
It's frustrating taking a test by someone who obviously knows less than
you
do....and doesn't know enough to write such a test.

Welcome to the Real World(tm) :)
e.g.

Question 10:

What is the size in bytes allocated for objects of the type SomeClass?


class SomeClass
{
public:
int x ;
int y ;
} ;

I don't know what 'their' answer is, but the real answer is:

sizeof(SomeClass) >= 4


-Mike
 
D

Dietmar Kuehl

Mike said:
I don't know what 'their' answer is, but the real answer is:

sizeof(SomeClass) >= 4

Nope. 'sizeof(SomeClass) >= 2': on platforms for 'sizeof(int)'
is identical to 'sizeof(char)' there is no need to waste two
extra words. Of course, such platforms will use at least 16 bits
for each 'char' probably even more (e.g. 32 or 64). To be fair,
I have never worked on such a machine.
 
T

Tomás

I don't know what 'their' answer is, but the real answer is:

sizeof(SomeClass) >= 4


Implementation Defined.

The platform may choose to store the values by hooking up the computer to a
rain cloud, taking an electrode from the other side of the rain cloud, and
then running a cable to a space shuttle which is doing loops of our galaxy
at speeds approaching the speed of light. The space shuttle can have a
monkey on board with a pen and paper who writes down the values of the
variables.

As for:

sizeof(SomeClass) >= 4

Yes, this is correct, but who said anything about allocation?


-Tomás
 
D

Dietmar Kuehl

As for:

sizeof(SomeClass) >= 4

Yes, this is correct,

Nope. On machines where 'sizeof(char) == sizeof(int)' the class may
occupy only two words, i.e. 'sizeof(SomeClass) >= 2'.
 
T

Tomás

Nope. On machines where 'sizeof(char) == sizeof(int)' the class may
occupy only two words, i.e. 'sizeof(SomeClass) >= 2'.

Hmm...

Let's review the evidence.

1) A char must be at least 8-Bit.
2) An int must be at least 16-Bit.
3) Two int's must therefore be at least 32 bits.

sizeof(char) <= sizeof(int)

It's not impossible to have a system where:

sizeof(char) == sizeof(int)

Therefore, you're correct; the overall answer is:

sizeof(SomeClass) >= 2


-Tomás
 
J

Jerry Coffin

@newsread1.news.pas.earthlink.net>, (e-mail address removed)
says...

[ ... ]
I don't know what 'their' answer is, but the real answer is:

sizeof(SomeClass) >= 4

Not so -- sizeof(SomeClass) >= 2.

Int is required to be at least as large as char, but not
necessarily any larger. Some DSPs don't really provide
the hardware to work with anything smaller than 16 bits,
so they use that for both char and int.
 
D

Dietmar Kuehl

Tomás said:
It's not impossible to have a system where:

sizeof(char) == sizeof(int)

Some Cray machines running at least C (I'm not positive about C++)
used have 64 bit words. They could not address smaller words and
all basic data types (integers, floating points, pointers, enums,
etc.) consisted of exactly one word. Since memory is much less
expensive now I could imagine that there are still machines with
similar characteristics.
 
M

Mike Wahler

Dietmar Kuehl said:
Nope. 'sizeof(SomeClass) >= 2': on platforms for 'sizeof(int)'
is identical to 'sizeof(char)' there is no need to waste two
extra words.

Right. I should have written:

sizeof(SomeClass) >= 32 bits, and the number of bytes
depends upon CHAR_BIT.

-Mike
 
G

Greg

Steve said:
I have been doing C++ for 13 years and was asked to take an online-C++
programming test.

WHAT A JOKE!!!

It's frustrating taking a test by someone who obviously knows less than you
do....and doesn't know enough to write such a test.

e.g.

Question 10:

What is the size in bytes allocated for objects of the type SomeClass?


class SomeClass
{
public:
int x ;
int y ;
} ;

The answer is clear:

sizeof(SomeClass)

is the size in bytes of the class SomeClass. Next question?

Greg
 
S

Steve Fox

I'll give you another one. How would you declare an integer variable whose
maximum value can be 32,767?

int x ;
unsigned int x ;
short x ;
unsigned short x ;
 
J

Jim Dye

The answer is clear:

sizeof(SomeClass)

is the size in bytes of the class SomeClass. Next question?

Not one of the answers. :)


Yet another one...

There was a question about an inline function asking what does the compiler
do with it in a call to the function.

One of the answers was that it calls the function.
Another was that it expands the function instead of calling it.
 
D

Dietmar Kuehl

Steve said:
I'll give you another one. How would you declare an integer variable whose
maximum value can be 32,767?

int x ;
unsigned int x ;
short x ;
unsigned short x ;

The question is ambiguous: is it asking for a data type which can
hold values up to and including 32767 (but possibly also more) or
one which is restricted to a maximum value of 32767. The latter
question is nonsense because C++ only define lower limits but no
upper limits and the former question is context sensitive: for a
counter, the correct answer is 'int', for data in an object the
correct answer depends on the usage pattern and is either 'int'
or 'short' depending on whether there are few object possibly used
heavily or many objects and thus only use relatively rarely.
 
S

skaller

Nope. On machines where 'sizeof(char) == sizeof(int)' the class may
occupy only two words, i.e. 'sizeof(SomeClass) >= 2'.

You're all wrong! The answer is

"What class?"

Because that stuff above is NOT a C++ program.
ISO C++ only specifies the semantics of a complete program,
and even that is indirectly by constraints on the translator.
 
S

skaller

Let's review the evidence.

1) A char must be at least 8-Bit.
2) An int must be at least 16-Bit.

You are getting confused with C.
C++ conformance model does not have any hard limits.
 
J

Jerry Coffin

@users.sourceforge.net>, (e-mail address removed)
says...
You are getting confused with C.
C++ conformance model does not have any hard limits.

Are you saying that the values required to be present in
<climits> aren't required to mean anything?
 
G

Greg

skaller said:
You're all wrong! The answer is

"What class?"

Because that stuff above is NOT a C++ program.
ISO C++ only specifies the semantics of a complete program,
and even that is indirectly by constraints on the translator.

And that answer would certainly get you hired.

In fact I can imagine after a few weeks on the job as a C++ programmer,
your manager comes to you with a few questions about some class you
implemented. Of course you can promptly cut this exchange short: "What
class? All that stuff I wrote is NOT a C++ program. ISO C++ only
specifies the semantics of a complete program, and even that is
indirectly by constraints on the translator."

What better answer could there be?

Greg
 
M

mahurshi

Steve said:
I have been doing C++ for 13 years and was asked to take an online-C++
programming test.

WHAT A JOKE!!!

It's frustrating taking a test by someone who obviously knows less than you
do....and doesn't know enough to write such a test.

e.g.

Question 10:

What is the size in bytes allocated for objects of the type SomeClass?


class SomeClass
{
public:
int x ;
int y ;
} ;

What are the choices? hehe ;-)

Mahurshi Akilla
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top