Introduction to Geotechnical Engineering II

Similar documents
0. 표지에이름과학번을적으시오. (6) 1. 변수 x, y 가 integer type 이라가정하고다음빈칸에 x 와 y 의계산결과값을적으시오. (5) x = (3 + 7) * 6; x = 60 x = (12 + 6) / 2 * 3; x = 27 x = 3 * (8 / 4


C++-¿Ïº®Çؼ³10Àå

step 1-1

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074>

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

금오공대 컴퓨터공학전공 강의자료

untitled

歯9장.PDF

강의10

Microsoft PowerPoint - ch07 - 포인터 pm0415

K&R2 Reference Manual 번역본

Microsoft PowerPoint - chap05-제어문.pptx

untitled

C프로-3장c03逞풚

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx

휠세미나3 ver0.4

목차 포인터의개요 배열과포인터 포인터의구조 실무응용예제 C 2

untitled

Page 2 of 6 Here are the rules for conjugating Whether (or not) and If when using a Descriptive Verb. The only difference here from Action Verbs is wh

PowerPoint 프레젠테이션

Chapter_06


Page 2 of 5 아니다 means to not be, and is therefore the opposite of 이다. While English simply turns words like to be or to exist negative by adding not,

chap7.PDF

OCW_C언어 기초

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

DIY 챗봇 - LangCon

1

歯7장.PDF

PowerPoint 프레젠테이션

컴파일러

- 2 -

슬라이드 1

구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined data types) : 다양한자료형을묶어서목적에따라새로운자료형을

Microsoft PowerPoint - chap06-2pointer.ppt

11¹Ú´ö±Ô

슬라이드 1

C# Programming Guide - Types

Hi-MO 애프터케어 시스템 편 5. 오비맥주 카스 카스 후레쉬 테이블 맥주는 천연식품이다 편 처음 스타일 그대로, 부탁 케어~ Hi-MO 애프터케어 시스템 지속적인 모발 관리로 끝까지 스타일이 유지되도록 독보적이다! 근데 그거 아세요? 맥주도 인공첨가물이

하나님의 선한 손의 도우심 이세상에서 가장 큰 축복은 하나님이 나와 함께 하시는 것입니다. 그 이 유는 하나님이 모든 축복의 근원이시기 때문입니다. 에스라서에 보면 하나님의 선한 손의 도우심이 함께 했던 사람의 이야기 가 나와 있는데 에스라 7장은 거듭해서 그 비결을

_KF_Bulletin webcopy

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi

Microsoft PowerPoint APUE(Intro).ppt

chap7.key

untitled

Microsoft PowerPoint - [2009] 02.pptx

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3

03장.스택.key

Microsoft PowerPoint - chap10-함수의활용.pptx

PowerPoint 프레젠테이션

02 C h a p t e r Java

슬라이드 1

int main(void) int a; int b; a=3; b=a+5; printf("a : %d \n", a); printf("b : %d \n", b); a b 3 a a+5 b &a(12ff60) &b(12ff54) 3 a 8 b printf(" a : %x \

13주-14주proc.PDF

PowerPoint 프레젠테이션

chap 5: Trees

<32B1B3BDC32E687770>

2002년 2학기 자료구조

Microsoft PowerPoint - ch07 - 포인터 pm0415

SIGPLwinterschool2012

A Dynamic Grid Services Deployment Mechanism for On-Demand Resource Provisioning

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

Week5

3. 1 포인터란 3. 2 포인터변수의선언과사용 3. 3 다차원포인터변수의선언과사용 3. 4 주소의가감산 3. 5 함수포인터

임베디드시스템설계강의자료 6 system call 2/2 (2014 년도 1 학기 ) 김영진 아주대학교전자공학과

11장 포인터

제 14 장포인터활용 유준범 (JUNBEOM YOO) Ver 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다.

<31342D3034C0E5C7FDBFB52E687770>

PowerPoint 프레젠테이션

Output file

Microsoft Word - FunctionCall

6주차.key

Microsoft PowerPoint - 27.pptx

비트와바이트 비트와바이트 비트 (Bit) : 2진수값하나 (0 또는 1) 를저장할수있는최소메모리공간 1비트 2비트 3비트... n비트 2^1 = 2개 2^2 = 4개 2^3 = 8개... 2^n 개 1 바이트는 8 비트 2 2

6.1 Addresses and Pointers Recall memory concepts from Ch2 ch6_testbasicpointer.c int x1=1, x2=7; double distance; int *p; int q=8; p = &q; name addre

PowerPoint Presentation

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

chap10.PDF

PL10

Microsoft PowerPoint - chap-06.pptx

Microsoft PowerPoint - Chapter_04.pptx

Columns 8 through while expression {commands} 예제 1.2 (While 반복문의이용 ) >> num=0

PowerPoint 프레젠테이션


0125_ 워크샵 발표자료_완성.key

Microsoft PowerPoint - chap03-변수와데이터형.pptx

Modern Javascript

02장.배열과 클래스

본문01

Microsoft PowerPoint - 제11장 포인터(강의)

Stage 2 First Phonics

untitled

프로그래밍개론및실습 2015 년 2 학기프로그래밍개론및실습과목으로본내용은강의교재인생능출판사, 두근두근 C 언어수업, 천인국지음을발췌수정하였음

<B3EDB9AEC1FD5F3235C1FD2E687770>

C 언어 프로그래밊 과제 풀이

#Ȳ¿ë¼®

DE1-SoC Board


No Slide Title

Transcription:

Fundamentals of Computer System - chapter 9. Functions 민기복 Ki-Bok Min, PhD 서울대학교에너지자원공학과조교수 Assistant Professor, Energy Resources Engineering

Last week Chapter 7. C control statements: Branching and Jumps C control statements: Branching ( 분기 ) if, else : important! & Easy! Switch ~ case C control statements: Jumps Continue, break, goto Logical operators ( 논리연산자 ): && Character I/O functions ( 문자입출력함수 ) getchar() and putchar()

if statement three general forms if (expression) statement if (expression) statement1 else (expression2) statement2 if (expression1) statement1 else if (expression2) statement2 else statement3

if statement general form (1) if (expression) statement a single statement or a single block with { } if value > 0 Branching statement ( 분기문 ) Test/execution is done only once while??? false true printf ( 양수입니다 n )

if statement general form (2) if (expression) statement1 else (expression) statement2 else if value > 0 true printf ( 음수입니다.\n ) printf ( 양수입니다 n )

if statement general form (3) if (expression1) statement1 else if (expression2) statement2 else if if value > 0 else statement3 else value < 0 true true printf ( 0 입니다.\n ) printf ( 음수입니다.\n ) printf ( 양수입니다 n )

if statement general form (3)

if statement general form (3) if (score < 1000) bonus = 0; else if (score < 1500) bonus = 1; else if (score < 2000) bonus = 2; else if (score < 2500) bonus = 3; else bonus = 4; Multiple levels up to 127

if statement pairing else with if if (number > 6) if (number <12) else When number is 5??? printf( You are close!\n ); printf( Sorry, you lose a turn!\n ); Very important to have proper indentations ( 띄어쓰기 )!

Character I/O functions ( 문자입출력함수 ) getchar() & putchar() - 단일문자 getchar() returns the next character from input ( 입력으로부터다음문자를리턴 ) No argument ch = getchar(); scanf( %c, &ch); putchar() prints its argument. putchar(ch); printf( %c, ch);

Logical operator &&! Operator Meaning && And Or! Not X Y X && Y X Y X! T T T T F T F F T F F T F T T F F F F T

Logical operator order of evaluation and range if (range >= 90 && range <= 100 ) printf( A\n ); if (90<= range <= 100 ) printf( A\n ); Don t do this! Semantic error! (90<= range) <= 100 always true 0 or 1

Conditional operator ( 조건연산자 )?:?: the only tertiary operator ( 삼항연산자 ) x = (y < 0)? y : y; If (y<0) x = -y; else x = y; General form Expression1? Expression2 : Expression 3 true ex) max = (a > b)? a : b; false

Loop Aids: Continue and break 처리의순서나흐름을조절하는제어문 continue: 해당루프의나머지를건너뛰고, 해당루프의다음사이클을시작. break: 어떤처리의순서나흐름을중단하고, 루프를탈출. 중첩구조에서는내부구조만영향을받음.

Continue and break while (( ch = getchar() )! EOF) { blabla(ch); if (ch == \n ) continue yakyak(ch); } blunder(n,m); while (( ch = getchar() )! EOF) { blabla(ch); if (ch == \n ) break; yakyak(ch); } blunder(n,m);

Multiple choices: switch ~ case switch (integer expression) { case constant1: statement1; expression & case label : integer (including char) No case label matches expression: default case constant2: statement2; } default: statements;

Multiple choices: switch ~ case Switch~case with break Switch~case without break

Multiple choices: switch ~ case Ex) Switch (choice) { case 1: case 2: printf( 파이팅!\n ); break case 3: printf( 잘했다!\n ) case 4: printf( 멋지다!\n ); break default: printf( 잘지내라.\n ); } choice = 1, 2, 3, 4, 5?

goto 조심해서쓸것 goto label;...... 변수이름규칙과동일 label: statement while (funct > 0) {.. } for (I = 1; I <=100; i++) { } help: xxx for (j = 1; j <=50; j++) { if(xxx) } goto help;

Today Chapter 9. Functions ( 함수 ) Functions and how to define them Arguments and return values ( 전달인자와리턴값 ) Function types ( 함수의데이터형 ) Declaring a function ( 함수선언 ) Recursion ( 재귀 ) Pointers : a first look

Functions What is it? Functions: a self-contained unit of program code designed to accomplish a particular task. 함수 : 하나의특정작업을수행하도록독립적으로설계된프로그램코드의한단위 Ex) printf(): causes data to be printed on your screen Strlen(): tells a program how long a certain string is. Why do we need it? Only one function can be used many times for repeated work. Imagine we write a program for printf() each time you need it. terrible!

Functions Why use it? Suppose you want to write a program that does the following. Read in a list of numbers Sort the numbers Find their average Print a bar graph Functions helps you concentrate on the program s overall design Using functions is more important than making them. ex) printf() #include <stdio.h> #define SIZE 50 Int main(void) { Float list (SIZE); Readlist(list, SIZE); Sort(list, SIZE); Average(list, SIZE); Bargraph(list, SIZE); Return 0; }

Analyzing the program Function prototype ( 함수프로토타입 ): tells the compiler what sort of function starbar() is Function call ( 함수호출 ): causes the function to be executed Function definition ( 함수정의 ): specifies exactly what the function does

Functions Declaration Any program that uses a function should declare the type before it is used 함수의데이터형미리선언. void starbar(void); - Function type - void indicate that there is no return value -Default is integer - declaration use ; - definition don t use ; - indicates that there is no argument ( 전달인자 ) This line announces that the program uses a type void function called starbar() & compiler expect to find the definition for this function elsewhere. May put this inside main()

Functions Calling a function Calls the function starbar() from main() by using its name followed by a semicolon Starbar(); When finished with the code within starbar(), the computer returns to the next line of the calling function main()

Functions Defining Defining starbar() is very similar to defining main() Uses { }, declare variables starbar(void) is not followed by ; - tell the compiler that you are defining. The variable count is a local variable. count can be used in main() without conflict.

Functions The program includes starbar() and main() in the same file. You may use two separate files. no return value no communication with calling function

Function Function argument ( 전달인자 )

Function Function argument ( 전달인자 ) Argument ( 전달인자 )

Functions Argument ( 전달인자 ) ch & num: argument ( 전달인자 ), formal argument ( 형식전달인자 ) or formal parameter ( 형식매개변수 ) ch: char type, num: int void show_n_char(ch, num); char ch int num Valid (but old style)

Functions Arguments ( 전달인자 ) SPACE, 8: actual argument ( 실전달인자 ) Formal parameter ( 형식매개변수 ): called functioin show_n_char() Actual argument ( 실질전달인자 ): calling function main()

Functions Arguments ( 전달인자 ) & return value Argument send information to functions. Calling function ex) main() argument Return value Function to be called

Functions Local and global variable ( 지역변수와전역변수 )

Returning a value from a function with return imin() returns min imin() 함수는 min 값을리턴함.

Functions Local and global variable ( 지역변수와전역변수 ) imin(n,m); lesser = min; Above expressions does not work main() has no idea what min is.

Functions return (n<m)? n : m same same return terminates the function If (n < m) return n; else return m;

Functions return Return value can be assigned to a variable, can be used as part of an expression. Ex) Answer = 2 * imin(z,zstar) + 25; Printf( %d\n, imin(-32+answer, LIMIT));

Function Function types You generally inform the compiler about functions by declaring them in advance should come before it is used. Function should be declared by type. A function with a return value should be declared the same type as the return value. If no type is given default is integer.

Functions prototype One way to omit a prototype putting entire definition before the first use int imax(int a, int b) { return a > b? a : b;} Int main() { z=imax(x,50); }

Recursion Recursion: calling itself ( 함수가자기자신을호출 )

Recursion

Recursion

Recursion

Recursion Recursion fundamentals Each level of function call has its own variables. Recursive function must contain soethingto halt the recursive calls.

Recursion tail recursion

Compiling programs with two or more source code files usehotel.c - Contains main() hotel.c - function definitions hotel.h

Compiling programs with two or more source code files Place the #define in a header file and use #include in each source code Header file contains the defined constants and function prototypes

Pointers: a first look What is it? Pointer: a variable whose value is a memory address 포인터는주소를값으로가지는변수이다. Char 형변수 문자 int 형변수 정수 포인터변수 주소 People: a name and a value Computer: an address (a computer s version of name) and a value

Pointers: a first look What is it? p 의값은 a 의주소이고, a 를가리킨다.

Pointers: a first look What is it? & operator gives you the address for a variable pooh = 24; pooh: 변수의이름, &pooh : 변수의주소 (ex. 0B76) Printf( %d %p\n,pooh,&pooh); 24 0B76

Pointers: a first look the indirection operator( 간접연산자 ) p = &a; b = *p; p 가가리키는주소의값 b = a ex) a = 3; p = &a; b = *p; //a 를가리키는포인터 //p 이가리키고있는주소의값을 b 에대입

Pointers: a first look declaring pointers pointer a; Above does not provide sufficient information. Various types take different amount of memory and some pointer operations require knowledge of that size. Int *a Char *a Float *a Space between * and the pointer name is optional.

Pointers: a first look Why do we need it? ( 왜필요할까?) How do we alter values in calling function? use pointer!

Pointers: a first look Why do we need it? ( 왜필요할까?) Send address instead of the values.

Pointers: a first look This is why ( 이래서필요하다 ) X 와 y 의주소를전달함으로써 interchange() 가그변수들에접근할수있게한다. 포인터와간접연산자 * 를사용함으로써함수는각각의주소에저장되어있는값들을구하고변경할수있게된다. 포인터는 interchange() 함수의변수들이지역적이라는사실을극복해준다. Main() 에손을뻗쳐저장되어있는값을변경.

Today Chapter 9. Functions ( 함수 ) Functions and how to define them Arguments and return values ( 전달인자와리턴값 ) Function types ( 함수의데이터형 ) Declaring a function ( 함수선언 ) Recursion ( 재귀 ) Pointers : a first look

Next week Chapter 10. Arrays and Pointers ( 배열과포인터 ) Arrays initialization, assignment, Multidimensional arrays Pointers and arrays Functions, Arrays, and Pointers Pointer operations