C + + Primer Plus version 6thSource Code---Compiler---target code---Connector (startup code-Library code)---executable codeSource code extension: C cc cxx C CPP C + +Compile and Link: Unix CC **.c------"**.O-----" a.outLinux g++ **.cxx need to link the library when the command: g++ **.cxx-lg++; compilation of multiple Files g++ 1.cxx 2.cxx If you modify 1.cxx, you need to compile the commandg++ 1.cxx 2.o re
intended to be represented.Method of finding Semantic Errors 1: Step-by-step execution of the program and get the results compared to the actual desired results. Of course, this method is cumbersome, but it is very good to find errors in the program. Naturally, for programs that need to iterate 10,000 times ... Please do not try it easily, but you can choose to trace some of the code for analysis;Method 2: Add print to the key point of the program to monitor the operation of the program.It is i
programming emphasizes being independent of a particular type. 6. C + + is Bjarne Stroustrup developed at Bell Labs in the year of the century , incorporating OOP(inspired by simula67 ) , generic programming, and traditional procedural methods. ? 1.3 Portability and standards ?1. portability There are two obstacles: hardware, language differences2. Ansi/iso is specifically responsible for the development of the C + + standard,c++98 is the first C + + standard. ? 1.4 Tips for creating programs
1th Chapter Preparation of knowledge1. Ritchie hopes to have a language that combines the efficiency of low-level languages, the ability to access hardware, and the versatility and portability of high-level languages, so he developed the C language based on the old language.2. After a certain degree of success in C + +, Stroustrup added a template, which makes it possible to perform generic programming.3. To support c++11 in Linux, compile the source file with the-STD = c++0x option:g++-std = c+
conversion function:
operator TypeName ();
Please note the following points:1) The conversion function must be a class method;2) The conversion function cannot specify a return type (TypeName is already given);3) The conversion function cannot have parameters (already implicitly provided);For example, the prototype converted to a double type is as follows: operator double ();19. Implicit conversion functions should be used sparingly. In principle, it is preferable to use an explic
constants enclosed in quotation marks, string constants that are described by pointers, they are handled by passing their addresses
Do not use string constants or pointers that are not initialized to receive input.
C + + has three ways of managing data memory:
Automatic storage--local variable--stack
Static storage, variables declared outside of a function or static storage, variables using the static keyword
Dynamic storage of variables---heap->new/delete declarations
[C ++ primer plus] [learning C ++ from Chapter 2]
2. c ++ basic statements
// Carrot. CPP -- C ++ basic statement # include
2.1 Definition and Declaration
I have never been able to clearly understand these two concepts before. Please clarify them now.
int b;
Defines an integer variable, that is, B is allocated with storage space suitable for integer variables.
At the same time, it is a declaration.
Based on regression, I feel that there is a clear explanation of the relationship between pointers and multi-dimensional arrays in C Primer Plus 5th. Therefore, this blog post is a supplement to the notes that have not been written down before.
------------------------------------------------------------ Split line ---------------------------------------------------------
For a simple discussion, we use a s
C ++ Primer Plus learning note-taking class initialization sequence base class constructor, destructor and operator functions operator = cannot be inherited by the derived class; then, when creating a derived class object, how do I call the base class constructor to initialize the base class data ??? The answer is: when executing the constructor, follow the sequence of First Brother (base class), then guest
Well, it's an entry level. It's a collection of small issues and easy-to-be-ignored things I 've made when learning this book.
At the same time, he expressed contempt for the predecessor who invented the notebook touchpad.
I am stupid. I have made a lot of problems before, but I am slow at sorting out ...........
I will review C primer plus and prepare for the next step of in-depth study of C language and d
("Your work time is%d\n", time);printf ("salary=%.1f tax=%.1f\n", salary,tax);Break ;Case 2:printf ("Input your Work time:\n");scanf ("%d", time);salary=calculate_salary (TIME,LEVEL2);Tax=calculate_tax (salary);printf ("Your work time is%d\n", time);printf ("salary=%.1f tax=%.1f\n", salary,tax);Break ;Case 3:printf ("Input your Work time:\n");scanf ("%d", time);salary=calculate_salary (TIME,LEVEL3);Tax=calculate_tax (salary);printf ("Your work time is%d\n", time);printf ("salary=%.1f tax=%.1f\n
1. How do I address the basic module of C?The C language contains one or more functions, and they are the basic modules of C.2. What is a syntax error and what is a semantic error?Grammatical errors are made by non-adherence to the grammar rules of the C language, and semantic errors are errors in meaning.3. Which of the following is the C keyword: main int function char =int Char4. Write a program that can produce the following output:smile! smile! smile!smile! smile!smile!Defines a string that
statements can be divided into 4 types: Declaration Statements, assignment statements (Assignment statements are special cases of expression statements), function statements, structured statements.4. Type conversionBasic rules for type conversions: 1. When the expression has char and short types, it is automatically converted to int and, if required, automatically converted to unsigned int. Under Kr C, float is automatically converted to double. 2. In any operation that contains two data types,
concept of a function from multiple parts. 4. One line.The third example code in the book is as follows#include "stdio.h" Void Butler (void); /* Iso/ansi C function prototype */int main (void) { printf ("I'll summon the butler funtion.\n"); Butler (); printf ("Yes, bring me some tea and writeable cd-roms.\n"); return 0;} void Butler (void) { printf ("You Rang, sir?\n");}The C90 standard adds a prototype, which is a declarative form that tells the compiler that you are using a spe
program to test the function.#include 5. Write a function. The visit function accepts the following parameters: the name of an int array, the size of an array, and a value that represents the number of picks. The function then randomly selects the specified number of elements from the array and prints them. Each element is selected at most once (draw or select a jury member). Also, if your implementation supports time () (described in the 12th chapter) or other similar functions, the output of
1. Print short, long, long long and unsigned#include intMainvoid) {unsignedintUN =3000000000; ShortEnd = $; LongBig =65537; Long LongVerybig =12345678908642; printf ("un =%u and not%d\n", UN, un);//U=udprintf"end =%hd and%d\n", end, end); printf ("big =%ld and not%hd\n", big, big); printf ("Verybig=%lld and not%ld\n", Verybig, Verybig); return 0;}Conclusion: Even if the variable itself is an unsigned type, you need to add u when printing, otherwise print according to the signed type; If you pri
templates:Template Class Trophy {...};where z is an int value, U is the type name, CL is a class template that uses TemplateClass templates can be partially materialized:Template Template Template The first declaration, which has the same two types, and a value of N of 6, creates a materialization. Similarly, the second declaration creates a materialization of the case where n equals 100, and the third declares that the second type is a pointer to the first type, creating a materialization.Temp
""P to process a PO, or Q to quit.\n"; } cout"bye\n"; return 0;}Effect:Please enter a to add a purchase order. P to process a PO, or Q to quit. Aenter a PO number to add:moonlightpoetplease enter a to add a purchase order. P to process a PO, or Q to quit. Aenter a PO number to add:moonlitplease enter a to add a purchase order. P to process a PO, or Q to quit. PPO #moonlit Poppedplease Enter a to add a purchase order. P to process a PO, or Q to quit. PPO #moonlightpoet Poppedplease Enter a to add
() !='\ n') Continue;}voidSinger::show ()Const{cout"category:singer\n"; Worker::show (); cout"Vocal Range:"Endl;}Listing 14.9 is a short program that tests these classes using a multiple array of pointers.Program Listing 14.9 Worktest.cpp//worktest.cpp--Test worker class hierarchy#include #include"worker0.h"Const intLIM =4;intMain () {Waiter Bob ("Bob Apple",314L,5); Singer Bev ("Beverly Hills",522L,3); Waiter W_temp; Singer s_temp; Worker* Pw[lim] = {bob, bev, w_temp, s_temp}; i
called first and then the accumulated destructor is called.If you want to use a class as a base class, you can declare members to be protected, not private, so that derived classes will have direct access to those members. However, using private members can often reduce the likelihood of programming problems. If you want a derived class to redefine a method of a base class, use the keyword virtual to declare it as virtual. This allows objects accessed through pointers or references to be handle
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.