본문 바로가기

C++

c++ call by value & call by refernce & const

#include<iostream>
using std::cout;
using std::endl;
using std::cin;

typedef struct _Person //개인정보의 구조체 정의
{
 int age;
 char name[20];
 char personalID[20];
}Person;

//typedef struct _Person person;

void  ShowData(Person p) //구조체 정보를 출력하는 함수 call by value
// void  ShowData(Person &p) //call by reference
// void  ShowData(const Person p) //레퍼런스 p를 통한 데이타 조작 허용금지: 상수화 시킨다(const)
{
 cout<<"******** 개인정보 출력 ********"<<endl;
 cout<<"이 름:"<<p.name<<endl;
 cout<<"주민번호:"<<p.personalID<<endl;
 cout<<"나  이:"<<p.age<<endl;
}

int main()
{
 Person man;

 cout<<"이 름: ";
 cin>>man.name;
 cout<<"나 이: ";
 cin>>man.age;
 cout<<"주민번호:";
 cin>>man.personalID;
 
 ShowData(man);
 return 0;
}

'C++' 카테고리의 다른 글

c ++ 수업중 정리 다 못한부분  (0) 2010.01.13
c++/c 언어 메모리의 동적 할당  (0) 2010.01.13
c++ 메모리의 동적할당 Debug_new.cpp p88  (0) 2010.01.13
call by value  (0) 2010.01.13
// call by reference  (0) 2010.01.13