0

Function Parameter, and Function Parameter Constant

anyone can tell me different about this code : #include <iostream> #include <string> using namespace std; string upc(string nn){ string tmp; for(size_t i = 0; i < nn.length(); i++){ tmp += toupper(nn[i]); } return tmp; } int main(){ string nama = "program c++"; cout << "Nama : " << nama << endl; cout << "upperCase : " << upc(nama) << endl; string *nn = &nama; *nn = "change program c++"; cout << "Pointer : " << upc(*nn) << endl; return 0; } ======================================================================== #include <iostream> #include <string> using namespace std; string upc(const string nn){ string tmp; for(size_t i = 0; i < nn.length(); i++){ tmp += toupper(nn[i]); } return tmp; } int main(){ string nama = "program c++"; cout << "Nama : " << nama << endl; cout << "upperCase : " << upc(nama) << endl; string *nn = &nama; *nn = "change program c++"; cout << "Pointer : " << upc(*nn) << endl; return 0; }

1st Jun 2020, 6:16 AM
Salman Al-Farisy
Salman Al-Farisy - avatar
2 Respuestas
0
Ok, i'll try it
1st Jun 2020, 6:51 AM
Salman Al-Farisy
Salman Al-Farisy - avatar