C++ Passing a local variable -
i can not figure out pointer wrong in code. however, receive error code not have pointer-to function.
#include <iostream> using namespace std; char uppercase (char ch) { if ((ch >= 'a') && (ch <= 'z')) { return ch - 'a' + 'a' ; cout << "your capital letter " << ch << endl; } else { return ch; cout << "your original letter is: " << ch << endl; } } int main(int& ch){ cout << "please enter lowercase letter between z: "; cin >> ch; char uppercase; char outchar; char inchar; outchar = uppercase(inchar); system("pause"); }
int main(char&)
not strictly-conforming. may provided implementation don't know of platform doing this. on hosted implementation, useint main()
orint main(int argc, char** argv)
instead.building on 1st note, declare
ch
in function local variable , usechar
notint
:char ch;
or remove completely, described in 4th point.
you call
uppercase
on uninitialized variable (inchar
), resulting in undefined behavior becauseuppercase
reads it. removech
variable , usecin
oninchar
instead.you should exchange
return ch;
cout
-statement inuppercase
function.cout
-statement dead code, meaning never executed because function returns beforehand.
Comments
Post a Comment