SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
7. 중간정리
차례
•
•
•
•
•

프로그래밍 시작 : 자료형과 연산자
조건문, 반복문, 네임스페이스
고급변수 사용
논리적 자료 표현 : 구조체
함수

2/25
프로그래밍 시작 : 자료형과 연산자
• 문제 분석을 통해 다룰 자료 식별 및 자료형 결정
• 변수 및 상수(constant)의 data type

• 자료형

• 정수형 : signed, unsigned

• char, int (short, long, long long) – CPU, OS, 컴파일러에 의존적

• 실수형 : 항상 signed

• float, double, long double (위와 같이 의존적)

• Bool형
• 유도형 : struct, union, enum
• char

• ASCII 문자 저장용
• 기본 128 + 확장 128
• BCD 코드로 처리 못하는 특수문자 등을 표현하기 위함
3/25
프로그래밍 시작 : 자료형과 연산자
* GNU C++ : type_traits.h 에 사용가능한 변수타입이,
numeric_traits.h에 사용가능한 변수범위가 정의되어 있다.

• u, l, ul의 suffix 를 이용하여 상수의 data type을 엄밀히 구분할 수
있음
• 100L, 72ul

• 문자열도 상수이다(constant 이므로)

• 연산자
• 산술연산자, 관계연산자, 논리연산자, 비트연산자

4/25
조건문
• 조건문 if, switch~case
if (조건식)
조건이 참이면 수행할 문장;
if (조건식)
조건이 참이면 수행할 문장;
else
조건이 거짓이면 수행할 문장;
if (조건식1)
조건식1이 참이면 수행할 문장;
else if (조건식2)
조건식2가 참이면 수행할 문장;
else if (조건식3)
조건식3이 참이면 수행할 문장;
………
else
조건 모두 만족되지 못할 경우 수행할 문장;

switch (수식)
{
case 상수1:
수식의 결과가 상수1일 때 수행할 내용;
case 상수2:
수식의 결과가 상수2일 때 수행할 내용;
case 상수3:
수식의 결과가 상수3일 때 수행할 내용;
case 상수4:
수식의 결과가 상수4일 때 수행할 내용;
……
default :
수식 결과가 주어진 case에 모두 만족되지 않을
경우 수행할 내용;
}
5/25
반복문
• for, while, do~while
for (초기화 ; 조건문 ; 증감문)
{
반복할 내용들;
}
while (조건문)
{
반복할 내용들;
}
do
{
반복할 내용들;
} while (조건문);

break, continue
6/25
네임스페이스
• 네임스페이스
• 블록 이름으로 범위 내에 변수 함수 모두 선언, 정의가 가능하다.
• 범위 연산자(::)를 통해 해당 범위 내의 멤버 참조 가능
namespace A_RANGE
{
int score=100;
int TEST(const int s)
{
return s/10;
}
}
using namespace A_RANGE;

7/25
고급변수 사용 1

레퍼런스 변수

8/25
고급변수 사용 2
• 배열변수 – 연속적인 기억공간
int a=100, i;
int *pa=&a;
int arr[5]={1,2,3,4,5};

• 메모리 동적 할당

9/25
고급변수 사용 2
• 변수, 함수의 선언 규칙

• static const unsigned int * a = 100;
• Specifier
• type specifier
• type qualifier : const, volatile
• storage class specifier

• Modifier : *, [], ()
• Identifier : 변수이름
• Initializer : rvalue
10/25
고급변수 사용 2
• Modifier
• Int *a
• 주소화

• Int a[3];
• 집합화

• Int a(int b);
• 함수화

• 무한확장 가능!
• Int *(*a[4])(int *);
11/25
고급변수 사용 2
• 연산자 우선순위 규정
• 1. 단항우선
• 단항연산자 -> 이항 -> 삼항 -> 대입 -> , 연산자

• 2. 후치 우선
• 후치 -> 전치

• 3. 근치 우선
• 가까운 단항 -> 먼 단항

• *--(*b)[3](3,4);
• *(--(*b)[3])(3,4);
12/25
고급변수 사용 2
• 변수의 해석
• Int *a[4];
• 1. token 분리
• 2. 우선순위 배정
• 3. identifier 부터 해석

• a는 int 를 가리키는 주소 4개를 담을 수 있는 배열이다.
• * : 가리키는 데이터 타입 / 포인터가 가리키는 것 -> 차순위 modifier
• [] : 요소 수, 요소 타입 / 배열의 요소 -> 차순위 modifier
• () : return 타입 / 함수의 리턴 -> 차순위 modifier

13/25
고급변수 사용 2
Int *a[4];
a
int
a[0]

int *

a[1]

int *

a[2]

int *

a[3]

int *

int

int

int

14/25
고급변수 사용 2
• 연습
•
•
•
•
•
•
•
•

int **p
int *a[3]
int (*p)[3]
char *f(char)
char (*p)(char)
int a[3][4]
int *(*p)(void)
int *(*a[3])(void)
15/25
고급변수 사용 2
• 구조체의 동적 할당

16/25
고급변수 사용 2
• 동적구조체는 멤버 연산자(.)을 사용할 수 없다.
• 동적 구조체에는 이름이 없고, 그 구조체의 주소만 알기 때문!

• ps = new char [strlen(name) + 1];
• delete ?

17/25
논리적 자료의 표현 : 구조체
• 여러 항목을 하나로 묶어서 자료형으로 선언
•
•
•
•

멤버
멤버 참조 연산자 (.)
구조체 포인터형 변수의 멤버 참조 연산자 (->)
typedef 와 함께 사용

struct 태그명
{
구조체 멤버;

typedef struct
{
구조체 멤버;

} (변수이름);

} 재정의이름;

Struct
{
구조체 멤버;

typedef struct 태그명
{
구조체 멤버;

} 변수이름1;

} 재정의이름;

18/25
함수
• 함수
•
•
•
•

약속된 기능을 수행
표준 함수 = 표준 라이브러리 = 라이브러리 함수
사용자 정의함수
main()

• 함수 오버로딩(Overloading)
• 동일한 함수 이름이지만 매개변수가 다른 경우 함수 재정의 가능!!!

• Sizeof (int) ?
• sizeof는 연산자이며, 컴파일 타임에 값이 결정되어 상수화된다
19/25
함수
• 함수 등가포인터
• 함수 이름 대신
• (*p)

• int add(int, int);
• -> int (*p)(int, int);

• char *f(char *);
• -> char *(*p)(char *);
20/25
배열은?
• 배열 등가포인터
• 배열 이름 대신
• (*p)

• Int a[4];

• -> int *p;

• Int *a[4];

• -> int **p;

• Int a[2][3];

• -> (*p)[3];

21/25

Mais conteúdo relacionado

Mais procurados

이펙티브 C++ (7~9)
이펙티브 C++ (7~9)이펙티브 C++ (7~9)
이펙티브 C++ (7~9)
익성 조
 
Gpg gems1 1.3
Gpg gems1 1.3Gpg gems1 1.3
Gpg gems1 1.3
david nc
 
[2011 05 21] 4장 제어
[2011 05 21] 4장 제어[2011 05 21] 4장 제어
[2011 05 21] 4장 제어
Jong Pil Won
 
The C++ Programming Language 5장 포인터, 배열, 구조체
The C++ Programming Language 5장 포인터, 배열, 구조체The C++ Programming Language 5장 포인터, 배열, 구조체
The C++ Programming Language 5장 포인터, 배열, 구조체
해강
 

Mais procurados (20)

프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기
 
Start IoT with JavaScript - 6.함수
Start IoT with JavaScript - 6.함수Start IoT with JavaScript - 6.함수
Start IoT with JavaScript - 6.함수
 
2015 Kitel C 언어 강좌3
2015 Kitel C 언어 강좌32015 Kitel C 언어 강좌3
2015 Kitel C 언어 강좌3
 
6 function
6 function6 function
6 function
 
Modern effective cpp 항목1
Modern effective cpp 항목1Modern effective cpp 항목1
Modern effective cpp 항목1
 
C review
C  reviewC  review
C review
 
이펙티브 C++ (7~9)
이펙티브 C++ (7~9)이펙티브 C++ (7~9)
이펙티브 C++ (7~9)
 
Javascript 함수(function) 개념, 호출패턴, this, prototype, scope
Javascript 함수(function) 개념, 호출패턴, this, prototype, scopeJavascript 함수(function) 개념, 호출패턴, this, prototype, scope
Javascript 함수(function) 개념, 호출패턴, this, prototype, scope
 
1. alps c&c++
1. alps c&c++1. alps c&c++
1. alps c&c++
 
Gpg gems1 1.3
Gpg gems1 1.3Gpg gems1 1.3
Gpg gems1 1.3
 
이펙티브 C++ 스터디
이펙티브 C++ 스터디이펙티브 C++ 스터디
이펙티브 C++ 스터디
 
[2011 05 21] 4장 제어
[2011 05 21] 4장 제어[2011 05 21] 4장 제어
[2011 05 21] 4장 제어
 
Start IoT with JavaScript - 2.연산자
Start IoT with JavaScript - 2.연산자Start IoT with JavaScript - 2.연산자
Start IoT with JavaScript - 2.연산자
 
Go
GoGo
Go
 
[Swift] Protocol (1/2)
[Swift] Protocol (1/2)[Swift] Protocol (1/2)
[Swift] Protocol (1/2)
 
스파르탄스터디 E04 Javascript 객체지향, 함수형 프로그래밍
스파르탄스터디 E04 Javascript 객체지향, 함수형 프로그래밍스파르탄스터디 E04 Javascript 객체지향, 함수형 프로그래밍
스파르탄스터디 E04 Javascript 객체지향, 함수형 프로그래밍
 
Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1Start IoT with JavaScript - 4.객체1
Start IoT with JavaScript - 4.객체1
 
The C++ Programming Language 5장 포인터, 배열, 구조체
The C++ Programming Language 5장 포인터, 배열, 구조체The C++ Programming Language 5장 포인터, 배열, 구조체
The C++ Programming Language 5장 포인터, 배열, 구조체
 
Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체
 
이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디
 

Destaque

10장 문자열클래스와파일클래스
10장 문자열클래스와파일클래스10장 문자열클래스와파일클래스
10장 문자열클래스와파일클래스
웅식 전
 
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class7. variable scope rule,-storage_class
7. variable scope rule,-storage_class
웅식 전
 
2 2. operators
2 2. operators2 2. operators
2 2. operators
웅식 전
 
12 1. multi-dimensional array
12 1. multi-dimensional array12 1. multi-dimensional array
12 1. multi-dimensional array
웅식 전
 
11. array & pointer
11. array & pointer11. array & pointer
11. array & pointer
웅식 전
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io
웅식 전
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main
웅식 전
 

Destaque (9)

7. arrays
7. arrays7. arrays
7. arrays
 
6. function
6. function6. function
6. function
 
10장 문자열클래스와파일클래스
10장 문자열클래스와파일클래스10장 문자열클래스와파일클래스
10장 문자열클래스와파일클래스
 
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class7. variable scope rule,-storage_class
7. variable scope rule,-storage_class
 
2 2. operators
2 2. operators2 2. operators
2 2. operators
 
12 1. multi-dimensional array
12 1. multi-dimensional array12 1. multi-dimensional array
12 1. multi-dimensional array
 
11. array & pointer
11. array & pointer11. array & pointer
11. array & pointer
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main
 

Semelhante a 7 mid term summary

NHNNEXT 개경프14 Subway Rocket Team Study 3rd C++
NHNNEXT 개경프14 Subway Rocket Team Study 3rd C++NHNNEXT 개경프14 Subway Rocket Team Study 3rd C++
NHNNEXT 개경프14 Subway Rocket Team Study 3rd C++
Min-soo Park
 
읽기 좋은 코드가 좋은 코드다 Part one
읽기 좋은 코드가 좋은 코드다   Part one읽기 좋은 코드가 좋은 코드다   Part one
읽기 좋은 코드가 좋은 코드다 Part one
Ji Hun Kim
 
[아꿈사] The C++ Programming Language 13장 템플릿
[아꿈사] The C++ Programming Language 13장 템플릿[아꿈사] The C++ Programming Language 13장 템플릿
[아꿈사] The C++ Programming Language 13장 템플릿
해강
 

Semelhante a 7 mid term summary (20)

C++ Advanced 강의 5주차
C++ Advanced 강의 5주차C++ Advanced 강의 5주차
C++ Advanced 강의 5주차
 
NHNNEXT 개경프14 Subway Rocket Team Study 3rd C++
NHNNEXT 개경프14 Subway Rocket Team Study 3rd C++NHNNEXT 개경프14 Subway Rocket Team Study 3rd C++
NHNNEXT 개경프14 Subway Rocket Team Study 3rd C++
 
04장 고급변수 사용
04장 고급변수 사용04장 고급변수 사용
04장 고급변수 사용
 
Let's Go (golang)
Let's Go (golang)Let's Go (golang)
Let's Go (golang)
 
Linq
LinqLinq
Linq
 
C Language For Arduino
C Language For ArduinoC Language For Arduino
C Language For Arduino
 
자바 8
자바 8자바 8
자바 8
 
05장 논리적 자료표현: 구조체
05장 논리적 자료표현: 구조체05장 논리적 자료표현: 구조체
05장 논리적 자료표현: 구조체
 
06장 함수
06장 함수06장 함수
06장 함수
 
Java_02 변수자료형
Java_02 변수자료형Java_02 변수자료형
Java_02 변수자료형
 
Java 변수자료형
Java 변수자료형Java 변수자료형
Java 변수자료형
 
강의자료 2
강의자료 2강의자료 2
강의자료 2
 
2013 C++ Study For Students #1
2013 C++ Study For Students #12013 C++ Study For Students #1
2013 C++ Study For Students #1
 
GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)
GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)
GopherCon Korea 2015 - Python 개발자를 위한 Go (이경찬)
 
C++ Advanced 강의 1주차
C++ Advanced 강의 1주차C++ Advanced 강의 1주차
C++ Advanced 강의 1주차
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기
 
Python programming for Bioinformatics
Python programming for BioinformaticsPython programming for Bioinformatics
Python programming for Bioinformatics
 
읽기 좋은 코드가 좋은 코드다 Part one
읽기 좋은 코드가 좋은 코드다   Part one읽기 좋은 코드가 좋은 코드다   Part one
읽기 좋은 코드가 좋은 코드다 Part one
 
ES6 for Node.js Study 2주차
ES6 for Node.js Study 2주차ES6 for Node.js Study 2주차
ES6 for Node.js Study 2주차
 
[아꿈사] The C++ Programming Language 13장 템플릿
[아꿈사] The C++ Programming Language 13장 템플릿[아꿈사] The C++ Programming Language 13장 템플릿
[아꿈사] The C++ Programming Language 13장 템플릿
 

Mais de 웅식 전

15 3. modulization
15 3. modulization15 3. modulization
15 3. modulization
웅식 전
 
12 2. dynamic allocation
12 2. dynamic allocation12 2. dynamic allocation
12 2. dynamic allocation
웅식 전
 
10. pointer & function
10. pointer & function10. pointer & function
10. pointer & function
웅식 전
 
5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing
웅식 전
 
5 1. character processing
5 1. character processing5 1. character processing
5 1. character processing
웅식 전
 
15 1. enumeration, typedef
15 1. enumeration, typedef15 1. enumeration, typedef
15 1. enumeration, typedef
웅식 전
 
3 2. if statement
3 2. if statement3 2. if statement
3 2. if statement
웅식 전
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
웅식 전
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io
웅식 전
 
2 1. variables & data types
2 1. variables & data types2 1. variables & data types
2 1. variables & data types
웅식 전
 
Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)
웅식 전
 
구름 기본 소개자료
구름 기본 소개자료구름 기본 소개자료
구름 기본 소개자료
웅식 전
 
Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)
웅식 전
 
13th chapter12 slide
13th chapter12 slide13th chapter12 slide
13th chapter12 slide
웅식 전
 
Week12 chapter11
Week12 chapter11 Week12 chapter11
Week12 chapter11
웅식 전
 

Mais de 웅식 전 (20)

15 3. modulization
15 3. modulization15 3. modulization
15 3. modulization
 
14. fiile io
14. fiile io14. fiile io
14. fiile io
 
13. structure
13. structure13. structure
13. structure
 
12 2. dynamic allocation
12 2. dynamic allocation12 2. dynamic allocation
12 2. dynamic allocation
 
10. pointer & function
10. pointer & function10. pointer & function
10. pointer & function
 
9. pointer
9. pointer9. pointer
9. pointer
 
5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing
 
5 1. character processing
5 1. character processing5 1. character processing
5 1. character processing
 
15 1. enumeration, typedef
15 1. enumeration, typedef15 1. enumeration, typedef
15 1. enumeration, typedef
 
4. loop
4. loop4. loop
4. loop
 
3 2. if statement
3 2. if statement3 2. if statement
3 2. if statement
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io
 
2 1. variables & data types
2 1. variables & data types2 1. variables & data types
2 1. variables & data types
 
Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)Goorm ide 교육용버전 for skku(학생)
Goorm ide 교육용버전 for skku(학생)
 
구름 기본 소개자료
구름 기본 소개자료구름 기본 소개자료
구름 기본 소개자료
 
Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)Goorm ide 소개 슬라이드(교육용 버전)
Goorm ide 소개 슬라이드(교육용 버전)
 
W14 chap13
W14 chap13W14 chap13
W14 chap13
 
13th chapter12 slide
13th chapter12 slide13th chapter12 slide
13th chapter12 slide
 
Week12 chapter11
Week12 chapter11 Week12 chapter11
Week12 chapter11
 

7 mid term summary

  • 2. 차례 • • • • • 프로그래밍 시작 : 자료형과 연산자 조건문, 반복문, 네임스페이스 고급변수 사용 논리적 자료 표현 : 구조체 함수 2/25
  • 3. 프로그래밍 시작 : 자료형과 연산자 • 문제 분석을 통해 다룰 자료 식별 및 자료형 결정 • 변수 및 상수(constant)의 data type • 자료형 • 정수형 : signed, unsigned • char, int (short, long, long long) – CPU, OS, 컴파일러에 의존적 • 실수형 : 항상 signed • float, double, long double (위와 같이 의존적) • Bool형 • 유도형 : struct, union, enum • char • ASCII 문자 저장용 • 기본 128 + 확장 128 • BCD 코드로 처리 못하는 특수문자 등을 표현하기 위함 3/25
  • 4. 프로그래밍 시작 : 자료형과 연산자 * GNU C++ : type_traits.h 에 사용가능한 변수타입이, numeric_traits.h에 사용가능한 변수범위가 정의되어 있다. • u, l, ul의 suffix 를 이용하여 상수의 data type을 엄밀히 구분할 수 있음 • 100L, 72ul • 문자열도 상수이다(constant 이므로) • 연산자 • 산술연산자, 관계연산자, 논리연산자, 비트연산자 4/25
  • 5. 조건문 • 조건문 if, switch~case if (조건식) 조건이 참이면 수행할 문장; if (조건식) 조건이 참이면 수행할 문장; else 조건이 거짓이면 수행할 문장; if (조건식1) 조건식1이 참이면 수행할 문장; else if (조건식2) 조건식2가 참이면 수행할 문장; else if (조건식3) 조건식3이 참이면 수행할 문장; ……… else 조건 모두 만족되지 못할 경우 수행할 문장; switch (수식) { case 상수1: 수식의 결과가 상수1일 때 수행할 내용; case 상수2: 수식의 결과가 상수2일 때 수행할 내용; case 상수3: 수식의 결과가 상수3일 때 수행할 내용; case 상수4: 수식의 결과가 상수4일 때 수행할 내용; …… default : 수식 결과가 주어진 case에 모두 만족되지 않을 경우 수행할 내용; } 5/25
  • 6. 반복문 • for, while, do~while for (초기화 ; 조건문 ; 증감문) { 반복할 내용들; } while (조건문) { 반복할 내용들; } do { 반복할 내용들; } while (조건문); break, continue 6/25
  • 7. 네임스페이스 • 네임스페이스 • 블록 이름으로 범위 내에 변수 함수 모두 선언, 정의가 가능하다. • 범위 연산자(::)를 통해 해당 범위 내의 멤버 참조 가능 namespace A_RANGE { int score=100; int TEST(const int s) { return s/10; } } using namespace A_RANGE; 7/25
  • 9. 고급변수 사용 2 • 배열변수 – 연속적인 기억공간 int a=100, i; int *pa=&a; int arr[5]={1,2,3,4,5}; • 메모리 동적 할당 9/25
  • 10. 고급변수 사용 2 • 변수, 함수의 선언 규칙 • static const unsigned int * a = 100; • Specifier • type specifier • type qualifier : const, volatile • storage class specifier • Modifier : *, [], () • Identifier : 변수이름 • Initializer : rvalue 10/25
  • 11. 고급변수 사용 2 • Modifier • Int *a • 주소화 • Int a[3]; • 집합화 • Int a(int b); • 함수화 • 무한확장 가능! • Int *(*a[4])(int *); 11/25
  • 12. 고급변수 사용 2 • 연산자 우선순위 규정 • 1. 단항우선 • 단항연산자 -> 이항 -> 삼항 -> 대입 -> , 연산자 • 2. 후치 우선 • 후치 -> 전치 • 3. 근치 우선 • 가까운 단항 -> 먼 단항 • *--(*b)[3](3,4); • *(--(*b)[3])(3,4); 12/25
  • 13. 고급변수 사용 2 • 변수의 해석 • Int *a[4]; • 1. token 분리 • 2. 우선순위 배정 • 3. identifier 부터 해석 • a는 int 를 가리키는 주소 4개를 담을 수 있는 배열이다. • * : 가리키는 데이터 타입 / 포인터가 가리키는 것 -> 차순위 modifier • [] : 요소 수, 요소 타입 / 배열의 요소 -> 차순위 modifier • () : return 타입 / 함수의 리턴 -> 차순위 modifier 13/25
  • 14. 고급변수 사용 2 Int *a[4]; a int a[0] int * a[1] int * a[2] int * a[3] int * int int int 14/25
  • 15. 고급변수 사용 2 • 연습 • • • • • • • • int **p int *a[3] int (*p)[3] char *f(char) char (*p)(char) int a[3][4] int *(*p)(void) int *(*a[3])(void) 15/25
  • 16. 고급변수 사용 2 • 구조체의 동적 할당 16/25
  • 17. 고급변수 사용 2 • 동적구조체는 멤버 연산자(.)을 사용할 수 없다. • 동적 구조체에는 이름이 없고, 그 구조체의 주소만 알기 때문! • ps = new char [strlen(name) + 1]; • delete ? 17/25
  • 18. 논리적 자료의 표현 : 구조체 • 여러 항목을 하나로 묶어서 자료형으로 선언 • • • • 멤버 멤버 참조 연산자 (.) 구조체 포인터형 변수의 멤버 참조 연산자 (->) typedef 와 함께 사용 struct 태그명 { 구조체 멤버; typedef struct { 구조체 멤버; } (변수이름); } 재정의이름; Struct { 구조체 멤버; typedef struct 태그명 { 구조체 멤버; } 변수이름1; } 재정의이름; 18/25
  • 19. 함수 • 함수 • • • • 약속된 기능을 수행 표준 함수 = 표준 라이브러리 = 라이브러리 함수 사용자 정의함수 main() • 함수 오버로딩(Overloading) • 동일한 함수 이름이지만 매개변수가 다른 경우 함수 재정의 가능!!! • Sizeof (int) ? • sizeof는 연산자이며, 컴파일 타임에 값이 결정되어 상수화된다 19/25
  • 20. 함수 • 함수 등가포인터 • 함수 이름 대신 • (*p) • int add(int, int); • -> int (*p)(int, int); • char *f(char *); • -> char *(*p)(char *); 20/25
  • 21. 배열은? • 배열 등가포인터 • 배열 이름 대신 • (*p) • Int a[4]; • -> int *p; • Int *a[4]; • -> int **p; • Int a[2][3]; • -> (*p)[3]; 21/25