Seungkyu Lee - khu.ac.krcvlab.khu.ac.kr/Lecture6.pdf · 2016-03-30 · 12 Program 4 This function...

Post on 23-May-2020

2 views 0 download

Transcript of Seungkyu Lee - khu.ac.krcvlab.khu.ac.kr/Lecture6.pdf · 2016-03-30 · 12 Program 4 This function...

[CSE10200] Programming Basis

(프로그래밍 기초)

Chapter 4-2

Seungkyu Lee

Assistant Professor, Dept. of Computer Engineering

Kyung Hee University

Functions in C++

User-Defined Functions

- Declaring, Calling, and Defining

Functions without Return Value

(Only Have Side Effect)

Functions with Return Value

Function Return Statements

Pass by Value

vs

Pass by Reference

Pass by Value

Different local

variables

Pass by Reference

A Bad Exchange

Calculate Quotient and Remainder

Program 4-8

Default Parameter Arguments

• Default values for parameters can be defined in function declaration

Program 4-9

Other Functions

Library Functions and the Linker

Standard Library Functions

Floor and Ceiling Functions

abs(), pow(), sqrt() and rand()

• abs(3) returns 3

• fabs(-3.4) returns 3.4

• pow(3.0, 4.0) returns 81 (3^4)

• pow(3.4, 2.3) returns 16.687893

• sqrt(25.0) returns 5.0

• rand()? srand()?

Scope for Global and Block Areas

Variables are in

scope from their

point of definition

until the end of

their function or

block.

Program 4-12

Program 4-13

Tips and Common Errors

Tips and Common Errors

Tips and Common Errors