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
chin function local variable , usecharnotint:char ch;or remove completely, described in 4th point.
you call
uppercaseon uninitialized variable (inchar), resulting in undefined behavior becauseuppercasereads it. removechvariable , usecinonincharinstead.you should exchange
return ch;cout-statement inuppercasefunction.cout-statement dead code, meaning never executed because function returns beforehand.
Comments
Post a Comment