C ++ FAQS Translation 3 (Part 2 Preliminary Knowledge Chapter 2 C ++ Grammar and Semantic Foundation)

xiaoxiao2021-03-06  40

The first part of the preparatory knowledge Chapter 2 C grammar and semantic basic problem 2.1 What is the purpose of this chapter? A: Introduce C basic grammar and semantics. This chapter provides a short overview of C grammar and semantics, covering most of the concepts, including: main () function, create and use local objects, dynamic objects, and static objects, pass the value, biography, and biography The address of the address passes the C object, the default parameter list, C input and output flow, the operator overload of the class, the use of the template, prevent memory leaks, exception handling, member functions, const member functions, constructor , Initialization list, sector, inheritance, IS-A conversion and dynamic binding, etc. Experienced C programmers can skip this chapter.

Question 2.2 MAIN () function is what is the point? A: It is one of the important functions of the application. Object-oriented C programs are almost all consisting of classes, however, at least one C language style function main (). Mian () is called when the program is executed, and when the main () function ends, the operating system will abort the operation of the program. The main () function always returns the int type, similar to the following form: Int main () {// ...} main () function has a feature: At the end, the default will return "0;". Therefore, even if the process occurs at the end of the main () function, the main () function can still return 0 to the operating system. Most operating systems will use the return value of Main () as a sign of normal end. The main () function is the only function that has an implicit 0 that is hidden at the end. Other functions must use explicit statements to return the appropriate value. In the example in this section, the main () function is no parameters, however, as in the C language, in order to be able to handle the command line of the program, the parameters of the main () function are optional. Question 2.3 What is the point of FUNTIONS? A: Functions is a function, which is an important way to break down software into smaller, manageable small pieces. Functions can have a return value (for example, the function gets a value by calculating and returning this value) or there is no return value. For functions that do not return values, its return value type is Void, which is often called the procedure. In the following example, the function f () does not have the parameters and the return value (ie, its return value is VOID), and the function G () has two integer parameters and a floating point return value. Void f () {// ...} float g (int x, int y) {float sum = x y; float avg = sum / 2.0; return avg;} int main () {f (); float z = G (2, 3);} Question 2.4 What is the main point of the default parameter? A: C allows the function with the default parameters. When the caller of the function does not give functions, the default parameter will provide the default value specified by the function. For example, the following example: If the caller does not provide the function f () provides input parameters, the integer 42 transmits the function f () as the default parameter. In this case, the default parameters of the function may make the caller's code look more concise.

转载请注明原文地址:https://www.9cbs.com/read-78203.html

New Post(0)