How to pass reference of a string to a function in C++

1 Answer

0 votes
#include <iostream>
#include <string>

using namespace std;

void string_by_reference(string &s);

int main()
{
	string s = "abcde";

	string_by_reference(s);

	cout << s << endl;

	return 0;
}

void string_by_reference(string &s)
{
	s = "xyz";
}

/*
run:

xyz

*/

 



answered Jun 10, 2017 by avibootz

Related questions

1 answer 116 views
1 answer 198 views
1 answer 175 views
2 answers 154 views
154 views asked Aug 22, 2022 by avibootz
...