Program language/C++

[C++] 구조체와 포인터

COSMOSRKSI 2021. 4. 22. 20:16

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

typedef struct _student {
char name[20];
int age;
}student;

void main()
{
student std1;
student* pstd1 = &std1;
cin >> pstd1->age;
cin >> pstd1->name;
cout << pstd1->age;
cout << pstd1->name;
}

 

-------------------------------

 

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

struct student {
char name[20];
int age;
};

void main()
{
struct student std1;
struct student* pstd1 = &std1;

cin >> pstd1->name;
cin >> pstd1->age;

cout << pstd1->name;
cout << pstd1->age;
}