Lecture Introduction to computer and programming - Lecture No 16

The contents of this chapter include all of the following: Discuss basic concepts related to concurrency, such as race conditions, OS concerns, and mutual exclusion requirements; understand hardware approaches to supporting mutual exclusion; define and explain semaphores; define and explain monitors. | CSC103: Introduction to Computer and Programming Lecture No 16 Previous lecture Pointer fundamental & operator * operator Pointer declaration Pointer type Today’s lecture outline Function call by address or pointer Function return value Recursive functions Function Calls Arguments can generally be passed to functions in one of the two ways: sending the values of the arguments sending the addresses of the arguments Example program 1 – function call by value Memory main() change_value() Program Output a = 10 b = 20 x = 20 y = 40 a = 10 b = 20 Press any key to continue Go to program 10 a 20 b 6504 7505 10 x 20 y 3205 4350 20 40 Example program 1 – function call by address Program Output a = 10 b = 20 x = 20 y = 40 a = 20 b = 40 Press any key to continue Go to program Memory main() change_value() 10 a 20 b 6504 7505 *x *y 3205 4350 *x change_value(6505, 7505); =*(6504) = 10 20 40 7505 6504 Example program 2-function call by value Go to program Example program 2-function call by address Go to program Return value of a function Points to remember Passing arguments by value is not the most efficient means for programming in C When arguments are passed by value, the called function is unable to modify the original contents of the incoming parameters When arguments are passed by address, the called function is able to modify the original contents of the incoming parameters A function only return a single value Example program Write a program in which a user input radius of a circle. The program calculates the area and the perimeter of the circle using a single function Write a program Conclusion If we want that the value of an actual argument should not get changed in the function being called, pass the actual argument by value. If we want that the value of an actual argument should get changed in the function being called, pass the actual argument by reference. If a function is to be made to return more than one value at a time then return these values indirectly by . | CSC103: Introduction to Computer and Programming Lecture No 16 Previous lecture Pointer fundamental & operator * operator Pointer declaration Pointer type Today’s lecture outline Function call by address or pointer Function return value Recursive functions Function Calls Arguments can generally be passed to functions in one of the two ways: sending the values of the arguments sending the addresses of the arguments Example program 1 – function call by value Memory main() change_value() Program Output a = 10 b = 20 x = 20 y = 40 a = 10 b = 20 Press any key to continue Go to program 10 a 20 b 6504 7505 10 x 20 y 3205 4350 20 40 Example program 1 – function call by address Program Output a = 10 b = 20 x = 20 y = 40 a = 20 b = 40 Press any key to continue Go to program Memory main() change_value() 10 a 20 b 6504 7505 *x *y 3205 4350 *x change_value(6505, 7505); =*(6504) = 10 20 40 7505 6504 Example program 2-function call by value Go to program Example program 2-function call by .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
8    90    1    13-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.