Stroustrup 5.9, exercise 6

A

arnuld

STATEMENT: define functions f(char), g(char&) and h(const char&). call
them with arguments 'a', 49, 3300, c, uc and sc where:

c = char
uc = unsigned char
sc = signed char

which calls are legal ?
which calls cause compiler to introduce temporary variable ?


ANSWER:

f('a') : legal
f(49) : legal but implicit conversion to from INT to CHAR
f(3300) : overflow in implicit conversion
f(c) : legal
f(uc) : legal but implicit conversion from "unsigned char"
to "char"
f(sc) : legal but implicit conversion from "signed char" to
"char"


in case of "g(char&)", only "g(c), g(uc) and g(sc)" will be legal

only the calls to "h(const char&)" will result inthe creation of a
"temporary variable". these will be legal:

h('a')
h(49)
h(3300)

may i know whether i am right or wrong ?
 

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
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top