Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 웹게임
- Spring
- phaser
- RDS
- express
- 블록체인
- 웹소켓
- CSS
- JSP
- 비트코인
- HTML
- tiles.xml
- 암호화
- EC2
- Ajax
- docker
- PL/SQL
- node.js
- model1
- autowired
- 도커
- AWS
- Servlet
- 알고리즘
- JavaScript
- SQL
- Cookie
- jQuery
- 배포
- websocket
Archives
- Today
- Total
記錄
C) 구조체 (3) 본문
출처 : https://www.youtube.com/watch?v=0T_QerEEjNA
구조체 접근하여 값 변경하기(구조체명으로 접근, 구조체 포인터 변수로 접근) 실습
#include <stdio.h>
#include <stdlib.h>
struct Books {
char Name[64];
char Author[32];
int Price;
};
int main(void){
// 선언 후 출력
struct Books book_1 = {"Harry Potter", "JK", 20000};
printf("Title : %s Author : %s Price : %d\n", book_1.Name, book_1.Author, book_1.Price);
// 값 접근하여 변경 - 구조체 명으로 직접 접근하여 값 변경
book_1.Price = 50000;
printf("Title : %s Author : %s Price : %d\n", book_1.Name, book_1.Author, book_1.Price);
// 값 접근하여 변경 - 구조체 주소로 접근하여 값 변경
struct Books* book_1_ptr = &book_1;
book_1_ptr->Price = 99000;
printf("Title : %s Author : %s Price : %d\n", book_1.Name, book_1.Author, book_1.Price);
return 0;
}
출력값
Title : Harry Potter Author : JK Price : 20000
Title : Harry Potter Author : JK Price : 50000
Title : Harry Potter Author : JK Price : 99000
'Computer language > C' 카테고리의 다른 글
C) 구조체 (2) (0) | 2017.12.21 |
---|---|
C) 구조체 (1) (0) | 2017.12.21 |
C) 배열과 포인터 (0) | 2017.12.21 |
C) 배열 (0) | 2017.12.21 |
C) 포인터 (0) | 2017.12.21 |
Comments