C/C++ 언어 구조체의 멤버 참조 이해를 위한 예제 프로그램


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* 구조체의 멤버 참조 이해를 위한 예제 프로그램 */
 
#include <stdio.h>
#include <string.h>
 
struct card {
  char *face; 
  char suit[20];
};
 
int main(void) {
  struct card a, *aPtr;
 
  a.face = "Ace";
  strcpy(a.suit, "Spades");
  aPtr = &a;
  printf("%s%s%s\n%s%s%s\n%s%s%s\n",
    a.face, " of ", a.suit,
    aPtr->face, " of ", aPtr->suit,
    (*aPtr).face, " of ", (*aPtr).suit);
  return 0;
}
 
cs


C/C++ 언어 구조체의 멤버 참조 이해를 위한 예제 프로그램



+ Recent posts