1 / 19

C-Language : Chapter 2

C-Language : Chapter 2. 2013, Fall Pusan National University Ki- Joune Li. Chapter 2: Type, Operator and Expression. Contents Constants and Variable Types Operators Expression. 1. Constants 와 Variables. Program 기본적인 과정 : Data 의 처리 Data 의 표현 Constant 와 Variable Constant

amena-johns
Télécharger la présentation

C-Language : Chapter 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C-Language : Chapter 2 2013, Fall Pusan National University Ki-Joune Li

  2. Chapter 2: Type, Operator and Expression • Contents • Constants and Variable • Types • Operators • Expression

  3. 1. Constants 와 Variables • Program • 기본적인 과정 : Data의 처리 • Data의 표현 • Constant 와 Variable • Constant • 주어진 값, 변하지 않는 값 • 예. 123, 24.0, ‘a’, “abc”

  4. 1. Constants 와 Variables 주기억 장치 • Variable • 변하는 값 • 반드시 주기억 장소에 값을 저장 • 예. x = 124; • x 의 값을 저장하는 주기억 장치에 123 이라는 값이 저장 • 변수 이름 • 영문으로 시작, 소문자/대문자 구별, 특수문자 사용 금지 123 x 변수 대입 상수

  5. 1. Constants 와 Variables • 변수의 값 지정 (Assignment) float x, y, z; x = 124; y = x; z = y = x;  왼쪽의 변수와 오른쪽의 변수가 서로 다른 의미 • Main Memory 주소 • von Neumann Machine

  6. 2. Data Type • Data Type • 연산의 방법을 명시 • 표현 및 저장 방법의 명시 • 예. • 5 / 2 = 2 • Integer : 2 bytes 로 표시 • Type의 종류 • Built-in Type : C 가 제공하는 Types • User-Defined Type : ,프로그래머가 정의하는 Types

  7. 2. Data Type – Built-In Types • Number • Integer : int, short, long, unsigned unsigned short, unsigned long • Float : float, double • Character • char : 1 character • char* : character string • Enumeration

  8. 2. Data Type – Type Declaration • 변수의 다음사항을 결정 • 표현방법 및 주기억 장치의 저장 크기 및 • 연산 방법 • Syntax TypeVariableName; 또는 Type VariableName= InitialValue;

  9. 2. Data Type – Array • 여러 개의 데이터를 저장하는 변수 • Syntax TypeVarableName[numberOfElements]; • 여러 개의 데이터를 반복적으로 처리할 경우 사용 • 예 int sum=0; inti, values[10]; /* ... value[0], ... value[9] */ for(i=0;i<10;i++) sum=sum+value[i];

  10. 2. Data Type – 그 외 • Enumeration Type • 단순히 값을 순서를 정하여 구별하기 위한 Type • Syntax enumVariableName {value1, value2, …, valuek}; • Register Type • 값을 주기억 장치가 아닌 Register에 기록 • 속도를 증가시키기 위한 방법 • Syntax register Type VariableName;

  11. 3. Operators • Operator의 종류 • Arithmetic Operators • Increment/Decrement Operators • Relational and Logical Operators • Bitwise Operators • Assignment Operators

  12. 3. Operators – Arithmetic Operators • Arithmetic Operators • 일반적인 산술연산 • +, -, *, /, % (나머지를 계산 : 예. 5 % 2 = 1) • Incremental Operators • a=a+1;  a++; 또는 a=a-1;  a--; • Post-increment vs. pre-increment a=10; b=++a; b=a++; printf(“%d %d\n”, a, b); printf(“%d %d\n”, a, b); • a+=4;

  13. 3. Operators – Relational Operators • Relational Operators (Comparison Operators) • 값의 비교를 위한 연산자 • <, >, <=, >=, !=, == • 연산의 결과 : False(0) 또는 True(0이 아닌 수) a=10; b=11; printf(“%d\n”, (a<b)); printf(“%d\n”, (a>b));

  14. 3. Operators – Logical Operators • Logic Operator • 논리적 연산을 위한 연산자 • &&, ||, ! • 연산의 결과 : False(0) 또는 True(0이 아닌 수) a=10; b=11; printf(“%d %d %d\n”, (a<b)&&(a>b), (a<b)||(a>b), !(a>b));

  15. 3. Operators – Bitwise Operators • Bitwise Operator • 값을 bit 단위로 처리하는 연산자 • &, |, ^, ~, <<, >> a=10; /*1010*/ b=11; /*1011*/ printf(“%d %d %d\n”, a|b, a&b, a^b); printf(“%d %d\n”, a<<1, a>>1);

  16. 3. Operators – Type Casting Operators • Type Casting Operator • 변수의 Type을 변경하는 연산자. • Syntax: (TypeName) variable float x=12.5, y=3.4; printf(“%f %d %d\n”, x/y, x/y, (int)x/(int)y);

  17. 3. Operators – Assignment Operators • Assignment 도 하나의 Operation float x=20.5, y;y=x;  결과는 Assign 된 값.printf(“%f \n”, y=x);

  18. 4. Expression • Expression 은 operator와 operand로 구성 • Operator의 우선순위(Precedence) • 연산의 순서를 결정 • Conditional Expression • X = cond ? value 1: value 2; • 예 X = a > 0 ? 10 : 20;

More Related