How to use char(type) in function

Hello guyz how are u? I have one problem here so let me show it here. As i know char type means 1 character in code and it need ' ' symbols and also I know that if u want more than 1 char symbol u must use an array so here I have seample code and please help me
here is code:

1
2
3
4
5
6
7
8
void string(char st[2]){
	cout << "hello world -->" << st << endl;
}
int main(int argc, char** argv) {

	string('hi');
  return 0;
}


but nothing heppening I have error. Help me if u can

Last edited on
You have several problems, did you compile your code? If so it would help if you posted the errors generated by your compiler (there should be several).

First in C there is a difference between a string constant and a character constant. A string constant can contain multiple characters and is enclosed within a pair double quotation marks. A character constant can contain only one character and this one character is enclosed within a pair single quotation marks.

Second C++ has a class named string, so it is not recommended that you use "string" as a function or variable name.

Third be careful, a string in C is an array of char terminated with the end of string character, make sure your C-strings have room for this termination character.



Topic archived. No new replies allowed.