A
arnuld
problem: define functions F(char), g(char&) & h(const char&). call
them with arguments 'a', 49, 3300, c, uc & sc where c is a char, uc is
unsigned char & sc is signed char. whihc calls are legal? which calls
cause the compiler to to introduce a temporary variable?
solution: this is the code
-----------------------------------------------------------
#include <iostream>
void f(char) {};
void g(char&){};
void h(const char&) {};
int main() {
char c;
unsigned char uc;
signed char sc;
f(c);
f(uc);
f(sc);
f('a');
f(49);
f(3300);
}
-----------------------------------------------------------
& the error is:
------------------------------------------------------------------------------
[arnuld@localhost cpp]$ g++ 05_ex-06.cc
05_ex-06.cc: In function 'int main()':
05_ex-06.cc:20: warning: overflow in implicit constant conversion
[arnuld@localhost cpp]$
---------------------------------------------------------------------------------
"f" accepts "char" & i know 'char' belongs to 'integeral types' as
'char' will be converted to an 'int'. it means 'f(49)' will be called
with whatever character 49 presents in ASCII table. am i right?
2nd, the error belongs to 'f(3300)' as 3300 is larger than one byte &
compiler expected an 'int' not larger than the size of 'char'. right?
them with arguments 'a', 49, 3300, c, uc & sc where c is a char, uc is
unsigned char & sc is signed char. whihc calls are legal? which calls
cause the compiler to to introduce a temporary variable?
solution: this is the code
-----------------------------------------------------------
#include <iostream>
void f(char) {};
void g(char&){};
void h(const char&) {};
int main() {
char c;
unsigned char uc;
signed char sc;
f(c);
f(uc);
f(sc);
f('a');
f(49);
f(3300);
}
-----------------------------------------------------------
& the error is:
------------------------------------------------------------------------------
[arnuld@localhost cpp]$ g++ 05_ex-06.cc
05_ex-06.cc: In function 'int main()':
05_ex-06.cc:20: warning: overflow in implicit constant conversion
[arnuld@localhost cpp]$
---------------------------------------------------------------------------------
"f" accepts "char" & i know 'char' belongs to 'integeral types' as
'char' will be converted to an 'int'. it means 'f(49)' will be called
with whatever character 49 presents in ASCII table. am i right?
2nd, the error belongs to 'f(3300)' as 3300 is larger than one byte &
compiler expected an 'int' not larger than the size of 'char'. right?