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"); } 

  1. int main(char&) not strictly-conforming. may provided implementation don't know of platform doing this. on hosted implementation, use int main() or int main(int argc, char** argv) instead.

  2. building on 1st note, declare ch in function local variable , use char not int:

    char ch; 

    or remove completely, described in 4th point.

  3. you call uppercase on uninitialized variable (inchar), resulting in undefined behavior because uppercase reads it. remove ch variable , use cin on inchar instead.

  4. you should exchange return ch; cout-statement in uppercase function. cout-statement dead code, meaning never executed because function returns beforehand.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -