I do not understand how the Function in C++ can be called. Is it right to call the function as under: Void ReadName() { char *name; cout<<"Enter your name: "; cin>>name; cout << "\nYour name is "<<name; void main() { ReadName(); return 0; }
you haven't allocated any space to store "name". right now, *name is a pointer that points to nothing. Code: void ReadName() { char *name = new char[20]; .... } one other thing, cin >> name will break on white space, so if you intend to ask for a string including spaces, then use cin.getline(name, space allocated to name); HTH
You can easily call any function without using pointer. You should define function as "int function_name(int a, int b)" and then put data types and variable in this function. After this, you can call this function in main() as “variable_name = funation_name(value1, value2)â€.