I don't see aa defined anywhere in your simple example case. Maybe you mean to do something like this?
#include <iostream>
void f1(char* data_in)
{
strcpy(data_in,"change");
}
int main()
{
char data_in[20];
f1(data_in);
std:: cout << data_in << std::endl;
}
Better still, using string...
#include <iostream>
#include <string>
void f1(std::string & data_in)
{
data_in = "change";
}
int main()
{
std::string data_in;
f1(data_in);
std:: cout << data_in << std::endl;
}
>> I also want to ask how do I write the function f1 that it would return a char answer[20] instead of a string?
An array can't be returned alone since it has no copy-constructor but you can encapsulate it in a struct
#include <iostream>
struct data_in_
{
char d[20];
};
data_in_ f1(data_in_ & data_in)
{
strcpy(data_in.d,"change")
return data_in;
}
int main()
{
data_in_ data_in1;
data_in_ data_in2 = f1(data_in1);
std:: cout << data_in2.d << std::endl;
}
Main Topics
Browse All Topics





by: star90Posted on 2009-06-25 at 17:23:03ID: 24717193
I also want to ask how do I write the function f1 that it would return a char answer[20] instead of a string?