View Single Post
  #1 (permalink)  
Old October 24th, 2004, 04:02 PM
gillianbc gillianbc is offline
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Basic char array and cin query.

Please look at the following:
Code:
#include <iostream.h> 
void GetInput(char name[15]); 
int main() 
{ 
  char word[15] = "Peter"; 
  cout << "Original word:" << word << endl; 
  GetInput(word); 
  cout << "Finally:" << word << endl; 
  return 0; 
} 
void GetInput(char name[15]) 
{ 
  cout << "Enter a name :"; 
  cin >> name; 
  name = "John"; 
  cout << "In function:" << name << endl; 
}
The output is :
Quote:
quote:
Original word:Peter
Enter a name:Fred
In function:John
Finally:Fred
So why did Fred persist and John didn't ?

(I'm very new to C++ so please be gentle)


Gill BC
__________________
Gill BC
Reply With Quote