functions with char

Hello everyone,

1 How can I pass a variable char to a function.
2 How can I return a variable char in the return of a function.

In this example is better explained, thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
char Hello();

int main()
{
	char texto[1000];
	cout << "Text:" << endl;
	cin >> texto;

	Hello(); //Here I want to pass the variable "texto"

	system("pause");
	return 0;
}

char Hello()
{
        cout << texto; // here I want to be able to print the variable "texto"
	return texto; // here I want to be able to return the variable "texto"
}


Again, thanks!
If you indeed want to pass and return a variable of type char then the declaration of a corresponding function could look as

char f( char );

However you are going to pass an object of type char[] that is an object of a compound type. In this case you could write

const char * f( const char * );
or
char * f( const char * );
or
char * f( char * );

and so on.


1
2
3
4
5
const char * Hello( const char *texto )
{
        cout << texto; // here I want to be able to print the variable "texto"
	return texto; // here I want to be able to return the variable "texto"
}
Last edited on
Topic archived. No new replies allowed.