Calling methods

Phương Pháp kêu gọi các phương pháp được gọi là tồn tại! Bạn gọi một phương pháp theo tên để yêu cầu nó để thực hiện nhiệm vụ của mình. Nếu phương pháp này đòi hỏi thông tin (theo quy định của thông số của nó), bạn phải cung cấp các thông tin yêu cầu. Nếu phương thức trả về thông tin (theo quy định của kiểu trả về của nó) | Calling Methods Methods exist to be called You call a method by name to ask it to perform its task. If the method requires information as specified by its parameters you must supply the information requested. If the method returns information as specified by its return type you should arrange to capture this information somehow. Specifying the Method Call Syntax The syntax of a C method call is as follows methodName argumentList The methodName must exactly match the name of the method you re calling. Remember C is a case-sensitive language. The argumentList supplies the optional information that the method accepts. You must supply an argument for each parameter and the value of each argument must be compatible with the type of its corresponding parameter. If the method you re calling has two or more parameters you must separate the arguments with commas. IMPORTANT You must include the parentheses in every method call even when calling a method that has no arguments. Here is the addValues method again int addValues int leftHandSide int rightHandSide . The addValues method has two int parameters so you must call it with two comma-separated int arguments addValues 39 3 okay You can also replace the literal values 39 and 3 with the names of int variables. The values in those variables are then passed to the method as its arguments like this int argl 99 int arg2 1 addValues arg1 arg2 If you try to call addValues in some other way you will probably not succeed for the reasons described in the following examples addValues compile time error no parentheses addValues compile time error not enough arguments addValues 39 compile time error not enough arguments addValues 39 3 compile time error wrong types The addValues method returns an int value. This int value can be used wherever an int value can be used. Consider these examples result addValues 39 3 on right hand side of an assignment showResult addValues 39 3 as argument to another method call The following exercise .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
2    777    2    14-05-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.