These two days often insomnia, sleep every 0 o'clock, but always wake up 4 o'clock. Wake up to sleep, then pick the lights. I spent 4 days, I finally finished Essential C . It is a bit rush, there is no fine buckle. After reading it, harvest well, and more confusion.
One feeling, C 's baggage is too heavy. He evolved from the process-based programming language, and it is necessary to compatibility with object-based programming, object-oriented programming, and generic style design, which is also included. This. It has brought a wide range of applications, but it also makes his language characteristics too much. Some are simply suppressed. Like a heavy historical burden, his language characteristics are also increasing The bigger it is, but the feeling of short and dry is not. It feels that the baggage of Java in the object is the lighter, which is a purely object-oriented programming language. It is not to say that Question, the author also has no intention to provoke another argument. It is just a speech.
The author is a pragmatic, such as the Dongdong, I would rather go with C Builder, and I don't want to use VC . It is not to say that VC cannot be used for image processing, but the DIB bit map class in VC. There is no good package, I look at the VC on the market about the image processing book, I have constructed a bit map class, then call it. I would rather use C Builder, it can at least let me focus on the algorithm Don't take things that read, display. On the contrary, the support of the driver and other low-level design, VC 's low-level support for Windows is unmatched by C Builder, of course, turned to VC . Of course, this also caused the author The software does not have a dilemma of proficiency. If you want to make a full-scale object system software, what reason I have to choose C , not to use Java? I didn't want to pass, I greeted some people I.
Here first, one of the people's reading notes, the author is SSSA2000, my finishing is written.
Reread Essential C Reading Note 1
A little time in the holiday, I plan to read Essential C this book. When I read this book, the time span was too big, causing it to have forgotten the front. I plan to focus on object-oriented.
By SSSA2000
7/24/2004
Chapter 1 C Programming Foundation
1, the definition and initialization of the object
In the book, we mentioned a rare initialization method. Generally, we are all like this:
INT A = 100; however, if there is a number of initial values, such as assigning a plurality of complexes, you need to have an imaginary and real part, then this method cannot be used, you can use the constructor assignment method: Complexa (2, 4) Give one of the complex variables A (2, 4), and the INT A = 100 is converted into this method: INT A (100).
2, arrays and vectors
Compare the statement of two containers:
Int a [10];
Vectora (10);
Vector is more flexible than Array, but initialization is convenient than VECTOR.
When you initialize, if you write this sentence, the compiler will prompt error: Vector (4) = (1, 2, 3, 4). Because Vector does not support initialization of this approach. Must this:
Vectora (4);
a [0] = 1;
a [1] = 2;
a [2] = 3;
a [3] = 4 ;;
Or use an array that has been initialized:
INT B [4] = {1, 2, 3, 4};
Vectora (B, B 4);
We know that the actual number of group names is the address of this array in memory, so it is passed to the VECTOR is the revelation and termination address of array B.
We can use A.Size () to get the size of the Vector, so the vector is more suitable for the length that is often changed.
3, still pointer
A few days ago, I wrote an article about the pointer in the C language. Here, I saw the pointer really kind. The book is mentioned in the book to detect the importance of the empty pointer. It can be seen that the master is not the same. I have seen a lot of books. I rarely mentioned that I have to detect the empty pointer. In fact, the empty pointer is very dangerous.
Suppose there are several of the following vector: a, b, c, and we need to access these four vectors in the program, can declare an array:
Vector * e [4] = {& a, & b, & c, & d}
Here, e is an array, type is vector * so we can operate these four vectors by e [i].
4, file read and write:
Mainly the specific application of streams.
#include
#include
#include
Main ()
{
String a = "hello", b = "world";
OFSTREAM OUTFILE ("1.TXT");
IF (! outfile)
CERR << "Unable to open file";
Else Outfile << a << b << endl;
} Of course, we can use OFStream Outfile ("1.txt", iOS_BASE :: App); to use the Append mode Here we use OFStream to write, we can of course use ifstream to read. Main () {string a = "hello", b = "world", c; ifstream infile ("1.txt"); if (! infile) cerr << "unable to open file"; else {infile >> C COUT << C;}} (Chapter 1) Chapter II: The process-oriented programming style has been very confused in the process-oriented object-oriented programming style, although there is already a deep understanding now. In fact, no matter what style, as long as it can better solve the problem is a good style. 1. Pass value and address: Lippman uses an exploration process when describing this problem, so that beginners have no obstacles that have been led by this issue. What is a ginseng? What is the argument? Simply put, the parameters illustrated when writing a function is a form, and the parameters when the function is called. When a function is called, a special area is created in memory, and the program stack is called. He offers a storage space without a function parameter. By default, the parameters will be copied in the incoming program, which is the so-called pass value, set to an array sort, and the way to use the value will not change the original number, this is to use it. site. Add a "&" in front of the parameter. When should I use to address? When you want to modify the incoming object, or if the incoming parameter object is too large, it will greatly improve the efficiency of the program. Of course, you can also use pointers to deliver parameters, which is also the same, because the nature of the pointer is the address. 2, Kymathe Dynamic Memory Management We know that the use of the New method can declare the dynamic memory space, do not know that it is easy to know what he mean from the literal. The variables declared with this method are not partially unsatisfactory, which is built on HEAP and can be destroyed at any time. For example, Int a [5] = new int [5]; use delete [] a when you want to destroy. Of course, improper use can cause Memory Leak. 3, default parameters: Use the default parameters to make us more flexible call functions, the default parameters have several rules: First, if we provide a default parameter, all parameters on the right side of this parameter should be the default parameters. So we have to put the default parameters on the right side. The default parameter can only be specified once, where the function declaration can be defined again, but cannot be specified in two places. In order to improve visibility, the author suggests that we are placed on the statement. 4. Why is the inline function? But when a function is called very frequently, this time the compiler will be very heavy, we can declare him to inline to make the compiler to expand the function to reduce the burden. Method: Adding inline before the original function. The definition of the inline function is often placed in the header file. 5. Use template: functoin template starts with keyword template, for example: Template Displading (const string & msg, const vector & vec) {.........} is also very simple: vectorivec; // Here you can be any type String MSG Display (MSG, IVEC); 6, function pointer: Function pointer brings us greater flexibility.