[Change] secondary school students in the C + + the way!

sponsored links
My educational level is not high, just an ordinary secondary school students, but I love programming! ! ! ! English and mathematics also my junior level! Learn C + + a year, quite a few detours, mainly because of buying the wrong book, I hope that my study guide can help those people like me.
[See the books mentioned in this guide]
Beginner Well, reading a line of Chinese students look at the best thinking of the book, here I recommend Transplantation and Hemopurification of C programming (second edition), this book is said to be Chinese, when the first contact with programming book, which is a suitable Introduction of a book. Remember that the programmers have seen the magazine article again, there is a Chinese program sectors of the masters <specifically who forget the> his beginner's programming, this book is on the title of the year, in-depth Xue once more, and I only saw half of the time, not very deep, did not question how to do it again too. Many people say that this book is fraught. . . I do not understand why anyone would say so.
Then started to learn C + +, and first bought a C + + Programming Language (Special Edition), said that time is really look at this book is like watching bible like to see when operator overloading is not watch anymore, At that time began to doubt their own intelligence has? ? Programming really so difficult? ? Later learned that this book is a about how to use C + +, that is a thought: It should be how to use it, how to use them well. When a person <beginner programmers> do not know the basic syntax of C + +, how can we understand this time? Looked really can not understand the situation a month, I saw someone recommended reading a line called Accelerated C + + Chinese version of the book, did not want to buy, and then a 3 tone on Monday, read, and read very faint, a lot of people say that this book was good, I still think this is still a garbage book, this book is only part of the C + + language features have been described, not widely spoken. I think not talking about the whole, wide enough books, better not read.
Money to buy a C + + Primer Plus (Fourth Edition) Chinese, this book really, I suppose I started a book, read the two months of reading, and behind the title have done most of the 700 pages are not fast. Reading this book is really on the C + +, have a comprehensive understanding of grammar, and exercises the back of this book have the answer, very good, very suitable for beginners. Reading this book, I type, operator overloading, friend really clear. Look after the C + + Programming Language (Special Edition) will also be able to understand.
Then I chose to study data structure, not to learn this, learn from the code efficiency, execution speed is very slow, very inefficient, here recommend a data structure algorithm and its application C + + language description, this book focuses hands, focus on applications, beginners should be more hands-on, very suitable for entry, then spotted the book because many hands before choosing it.
Here you can learn windows programming, and in school VC + + C #, etc., I think we should first take a look at Windows Programming (5th Edition) (two volumes), after reading this you will find VC + + is very simple! ! After reading this can learn a VC. Microsoft Visual C + +. NET Technology Insider (6th edition), some people say this book for beginners, but the buy back is good.
Finally, I want to tell you my experience of learning: I think the programming is a very practical science, nothing more than to see the code and write code for a process, the process of writing the code will be a lot of problems, do not be afraid of problems The more problems, more things will be learned, and these problems where you will remember very well. In the process of learning will see a lot of books, and sometimes have not read the time to read that some people inevitably will be very depressed <Most beginners should be>, I think the following words should be helpful to everyone : "to read the book, carefully read and understand book, the unpleasant task of looking. a lot of time to read the book, in fact you think you can not understand why they can not read." I do not see "C + + Primer Plus" before, do not know C + + has been the basic grammar of the circumstances Yes, see "C + + Programming Language (Special Edition)" come with a month's time. At that time, I only have C basis, so do not understand anything, then read the "C + + Primer Plus (Fourth Edition)" In the future, a new beginning to see "C + + Programming Language (Special Edition)", such a waste of money, but also wasting their time, so I want to tell you the experience of some books, hoping to help those new to: good book, there are some people say well, I have little experience, is looking for books in the rankings, a good book it will often list high, much to the textbook's website to see if users of the evaluation, there are more than 95 percent of them said the book is good, must be a good book.
Finally, I would also like to mention an entry in the book, C + + University Course (Second Edition) This book I feel like "C + + Primer Plus (Fourth Edition)" Positioning the same book, all that content than the latter which All, I have also gone up, it is easy to understand book answers back exercises are also available, is relatively rare in the matter, beginners can also consider this.

Advice to beginners on the programmer: Liu Wei

I still think that, for a beginner, IT industry can not catch up with the technology trend, and can not afford to catch up. I always saw my DDMM who threw the books to sell more expensive, such as C #, VB.Net so voluminous, it makes me feel very sad. Many do not know if the pointer is Zehui Shi's BBS Zhanyou exultant discussion C # which can not make me feel pointer so funny. ASP C # as the same year, "suddenly spring to such a night, Arcadia 10000 Pear Tree open" Consequently, many schools became the School of Information "Web Academy." 96,97-class many students have to do the Web. Of course, I did not sense any discrimination against a particular industry. I just feel that if they catch up with these fashionable technology of the time a little more basic courses should be able to go further on the.

Mistakes

Beginners wave to catch up on C # is actually just the learning process often encountered in one of several errors. I will use practical examples to illustrate these phenomena, you can step by step to see if they are not belong to one or several of them:

Programming of computer technology mean that:

Some people even do not have this idea in the subconscious urge to have it. I wonder is that many college students have the information that idea. Computer programming that is professional, has nothing to do with programming, or not all are related to the curriculum regardless of his extreme as long as the books do not mention the students with "programming" the word he would not see.

In fact, application of computer technology, programming is a complex process of the lowest labor, which is why the IT industry, the bottom of the programmers (CODER). Computer technology, including multimedia, computer networks, artificial intelligence, pattern recognition, management information systems, etc. in these areas. Programming is only in these specific works in theory or practice in the process of algorithm of the process. Programming, not necessarily on the knowledge of computer technology is high on the must. And an interesting phenomenon is that many masters of computer technology researchers who do not know programming. Internet hype and the reality of good working conditions and the programming of this work was a mystery. Actually, every programmer know that mind their own these things, when school is not difficult than any other profession, so naturally will not upscale to go.

The holes have been proper for us to style:

I have seen a girl's "Principles of Computer Networks" teaching, students like this girl, like in the book program filled with bars bars, full of notes done, print out some material is also thicker than that. I do not understand is, like the principles of computer networks such courses need to take notes? Our exam-oriented education does harm to many students in the "principle" when this type of course many students as the school "Marxist-Leninist principles" as a verbatim recitation of memory. I have seen this but the most foolish behavior. The so-called "principle", that is why it needs to do to master, learning why, rather than how (do). Extremely serious students memorize the maximum length of Ethernet cable, data frame length, the meaning of each field, IP header format and so on, but forgot the principles of routing, forgot to TCP / IP protocol for the purpose of . In short many people spend a lot of time to equal the book by heart but did not learn anything.

Learning to program is also the case when these students, they remember the exact syntax of C + + all the details. After reading the C + + tutorial to see "Thinking in C + +" (really good book), "Inside C ++"," C + + reference", this C + +, that C + + ... ..., then the online variety of C + + syntax anecdotes , and then found myself forgetting some of C + + syntax, and finally back to catching up .... There The Young told me that: "C + + too hard, learned the forgotten here, where a succession of forgotten science template." I replied: "You do not learn the easy." I did not teach him bad, just tell him to pull the dead C + + syntax and the hole has been showing off on the fennel beans flavored with aniseed There are several written word as meaningless. You do not need on the C + + syntax is too concerned about the hands-on programming it wants, there is no recall on the very spot where a search MSDN buttoned. I have a conclusion that the actual development process of the program is the most minimal understanding of grammatical knowledge. This is why I for students with Basic (I had never learned to it) when writing a small program, only took half an hour, looked at grammar, and then half an hour to complete a process, but an hour later I totally forgot all the keywords Basic.

Regardless of the basis, the blind pursuit of fashionable technology:

Finally point to the topic will come up. Most people want their stuff to immediately run up and turned into cash. Such ideas are a programmer has entered the vocational areas or project managers are reasonable and IT technological progress is so fast no follow-up is unemployment. But for beginners (especially a large enough time secondary school students), this idea is another person to understand. One does not enter into competition in the beginner to the largest capital is sufficient time to settle down his mind to learn the basic things to learn why, not how. Fashionable technologies are easy to grasp, but more and more easy to grasp, this is driven by commercial interests, in order to maximize the reduction of software development costs. However, in IT field is the reality, the more easy to grasp things, the more people learn, and out faster. Every new technology out, there are many beginners to follow up, these lack the necessary foundation for beginners while making their follow-up process in a lot of time, and so he learned, and which are quickly eliminated . Based curriculum, for example, data structures, operating systems, etc. Although the principle can not let you flew to implement a linux (which is useless theory course many people laughed at the reasons), but they can significantly reduce your learning curve when learning new technologies slope. And for many key technologies (for example, the design process Win32 SDK, DDK programming) is even indispensable.

I am a living example of one of my classmates, I can not find in the freshman boot button, he has to write some simple procedures for the compilation. I spent all the time sophomore compilation, computer architecture, data structures, operating systems theory and so on learning of these courses, and he began to learn HTML and VB, ASP, and catch up the trend. Junior year when I started learning Windows Operating System, SDK programming study, time is long enough then I can die like a decent VC to develop the application. I once because the program students have been able to run and she is still learning how to create a dialog box while regretting, but came to school only to find their choice is what's right. And I negotiated the company out of his salary is more than twice. Here is a very inappropriate example: Suppose learn VB programming needs 4 months, learning basic courses and VC programming needs for 1 year. So if you first learn VB, come to learn the latter, time will not be reduced, or a year, while the other hand, if the first study the latter, come learn VB, maybe you only need one week will be able to learn very skilled.

Several important basic course

If you are a student, or if you have enough time. I suggest that you carefully control the following knowledge. My advice is for those who want to be successful in the IT technology for beginners. At the same time I also listed some books, these books should still be in the bookstores. Indeed, I read an article **'s greatest wish is to books on a single list.

English - do not feel funny. I highly recommend this course because there is no reading of professional documents is unthinkable. English translation will often come out of these years, and now many publishers will gladly go directly to the E text of the printing. Learning is a teaching force yourself to look at original start will be read, with more skilled nature. Too bitter to eat under cruel absolutely need the quality of any industry.

Computer architecture and assembly language - a book on architecture are everywhere, but also very much the same, it touches on are a very good compilation of the book "80x86 Assembly Language Programming Guide" (Tsinghua University Press, black cover, Ji-Wen Yang book). You need to focus on learning the 386 protected mode after programming. If you study modern operating system when the bottom will feel something is watching bible.

Principles of computer operating system - our developers are always in a specific operating system, and if not, there is only one possibility: to achieve an operating system you own. In any case, the operating system principle is a must-read. It is like we are making a chip peripherals, the chip timing of basic work is necessary to understand. This is also a lot of books I do not see what the book is outstanding. Just think, after reading these books should be free to see if the "Inside Windows 2000" (Microsoft Press, I think the E version, the Chinese title must have Windows 2000 technology insider like it). On the need to learn it, ZDNET's another article has been discussed.

Data structures and algorithms - this course can determine a person's level of program design level, is a core curriculum. I preferred the Tsinghua version (Zhu war legislation, Liu days). Many people like to buy C + + version but I think there is no need. C + + syntax for algorithms process becomes more complicated, and many teachers like to use the modules that make things more complicated algorithm. Exception is that in learning C version of the book finished, and then later look at C + + version of the book is the best.

Software Engineering - This course is more to discover it was more important, though, when one started to see and Marxism as the same as unintelligible. My advice is to look at "Practical Software Engineering" (yellow, Tsinghua University). Do not spend too much time to remember old rules, can not read the jump. Every time they've accomplished in a software design task (either exercise or work), and then later recalled recalled every time a harvest.

Windows Programming - "University Press, Petzold of" I suggest that any attempt to design Windows program for people to learn VC careful study before its completion. And in front of that of the "Inside Windows 2000" is also the best time into the back of the book. In this book, not C + +, there is no GUI, no control. Some of that is how the original C language to complete the Windows programming. After school finished it, you will find that VC is very easy to learn. Do not read this book without learning in advance before the VC, you'd better not touch touch all. I know that many of the elite schools have even used it as a textbook for teaching. Shows its importance.

Several courses above I think it will be important in the course (if you want Windows programmers).

For other courses have such a simple selection method: If you are a computer system, please learn all your basic course. If not, please refer to computer science curricula. If you find yourself unable to imagine what will happen when reading a book, please turn end of the book to see if it references, to find them and learn from them, then look back at this book. If the title of a book with the "principle" word, you will not have to remember it the details, you should be at least 50 pages a day to master the essentials speed. As much as possible in a theoretical or practical computer algorithm.

You can also read many book reviews CSDN. The book reviews can help you decide what kind of book reading.

Day three provinces had almost too many books read every day, people get lost. Be sure to study every night think about what, and some things that need to know anything related to their own what the most interested in a book spent too long not enough so. Should also be more considerate, the most likely future applications, this can let you catch up with technology trends rather than leading the technology trend. Meanwhile, the effort has now mastered the use of technology and theory have some new ideas to create something. Persist in doing so allows you to truly become a software "developers" and not just a CODER.

To most of the time spent learning

This is the final advice for beginners. SC to play every week, or time compression to the CS at least, do not play their best. Also, if your ASP technology has been able to come to the money, even if the company you part-time, which prove your talent can ensure you to get better after learning the benefits, you should do more complex things. Long-term view of some, no matter to whom it is applicable.

I believe you have to decide whether or when learning C # to learn it.

c language programming style

Chapter I: indentation

Tab is 8 characters, thus indentations are also 8 characters. There are many strange style, they indentation is defined as 4 characters (set to 2 characters!) Depth, which is like trying to PI defined as 3 as unacceptable.

The reasons are: the size of indentation is to clearly define the beginning and end of a block. Especially when you have spent in front of the computer more than 20 hours later, you will find a large indentation makes your program understanding easier.

Now, there are some people that use 8-character indentations makes the code from the right side close to the 80-character terminal screen width is difficult to be watching proceedings. The answer is, but your program has more than 3 indented time, you should modify your program.

In short, 8-character indentations makes the program easy to read, there is an additional advantage is that it can become nested layers you will program the time to give you too many warnings. This time, you should modify your program .

Chapter II: The position of symbols

Another issue of C programming style is to brace treatment. Indentation with different sizes, there is little reason to choose one instead of another style, but there is a recommended style, it is the Kernighan and Ritchie's The classic book brings, it will start the final brace on the line, while the end of the brace on the first line, as follows:

if (x is true) (we do y)

However, there is a special case: name function: brackets is the beginning of the next line on the first, as follows:
int function (int x) (body of function)

People of all unorthodox criticism this inconsistency, but all right-thinking people understand that: (1st) K & R is the ___ of the ___, and (Second) K & R, if not, see article. ( :-))...... In addition, the function is special, need not be the same.

Note that the end of the bracket in its share of the line is empty, __ __ it apart with a statement as a continuation of the same symbol. Such as "while" in the do-while loop, or "else" in the if statement. as follows:

do (body of do-loop) while (condition);
And if (x == y) (..) else if (x> y) (...) else (....)

Reason: K & R.

Also, note that this brace placement method reduces the number of blank lines, but no less readable. Thus, the screen size is limited, you can have more blank lines to write some comments the.

Chapter III: Naming System

C is a concise language, then the name should be simple. ASCAL with MODULE-2 and the language is different, C programmers do not use such ThisVariableIsATemporaryCounter the like are named. A C language programmer will be the named "tmp", which is easy to write, and not so difficult to understand.

However, when the mixed type of the name had to appear when the descriptive name of the global variable is necessary for the. Call a name "foo" is a function of overall annoying. Global variables (only you have to use Only when the use of it), as a global function, as required descriptive naming. If you have a function used to calculate the number of active users, you should be so named - "count_active_users ()"-- or another similar the form, you should not name "cntusr ()".

There is a method known as the Hungarian name, it will function, the type of code to write the variable name in this way is a manifestation of defective brain --- the compiler knows the type but also to check it, but this will only confuse programmer. - Why know why Micro $ oft will produce so many "bugs" program has to!!.

Local variable names should be short and pithy. If you have a random integer loop counter, it is possible to have "i", if it can be made without any possible misunderstanding, then, to write "loop_counter" is inefficient. Similarly, "" tmp "can be any temporary values of function variables.

If you're afraid you confused the names of local variables, there is another issue, which is called
function-growth-hormone-imbalancesyndrome.

Chapter IV: Function

Function should be short and charming, but only for one thing. It should only cover one or two screens (80 * 24 1 screen), and only for one thing, and will do it well. (Is not that UNIX- style me, translators note).

The maximum length of a function and function is inversely proportional to the complexity and indentation size. So, if you have written a simple but a function of the length of long, and you have already done a lot of different situations very small things, write a function is a little longer does not matter.

However, if you write a very complex function, and you have estimated that if most people reading this function, he may not know what to say to this function, this time using the descriptive name of a help function.

Another consideration is the number of variables Jubu. They should not exceed 5-10, or you may be wrong. Zhongxin consider This function and bring them to Fenge into smaller functions. The human brain often can easily remember live in 7 different things, more than this number would cause confusion. you know you are very smart, but you may still want to know two weeks before to do.

Chapter 5: Notes

Notes is a good thing, but too many notes and dangerous, do not try to explain your area code is a comment on how how good: you should write better code, rather than spending a lot of time to explain those bad code.

Usually, your comment is explain what your code, not how to do. Moreover, to attempt to avoid comment inserted in a function body: if this function is indeed very complex, you need some of them Note, you should look back to Chapter IV. You can write a short note to indicate or warn those you think are particularly clever (or very ugly) part, but you have to avoid too much. Instead, the written comments before the function, telling people what to do in it, and possibly why.

Chapter VI: You have caught them up.

Do not worry. You have probably already accused The "GUN emacs" automatically to help you deal with C source code format, and you have seen it does so, however, the default case, it is not satisfactory the role of Huan Shi (In fact, they easily knocked out of something than even ugly - ainfinite number of monkeys typing into GNU emacs would never make a good program)

So, you can either do not use GUN emacs, or let it use sanervalules. To use the latter, you need to enter the following statement to your. Emacs file. (Defun linux-c-mode () "C mode with adjusted defaults for use with the Linux kernel. "(interactive) (c-mode) (c-set-style" K & R ") (setq c-basic-offset8))

This will define a Mx Linux-c-mode command. When you when hacking a module, how you will -*- linux-c -*- input in the beginning of two lines, this mode will automatically work. Moreover, You may want to join the following

(Setq auto-mode-alist (cons' ("/ usr / src / linux .*/.* \ \. [] Ch $". Linux-c-mode) auto-mode-alist))

To you. Emacs file, so that when you / usr / src / linux and edit the file, it automatically switches to linux-c-mode.

However, if you do not let emaces to automatically handle file formats, not nervous, you still have the same thing: "indent."

GNU indent is also very rigid format, which is why you need to add a few lines of command options. However, this is also not too bad, because the creator of GNU indent formats also remember the authority of K & R, (GNU is not the crime, They simply wrong in this matter guided by the people), you have to do is just enter the options "-kr-i8" (that "K & R, indented 8 characters).

"Indent" has a lot of features, especially when it recommended that you re-format your code, you should look at the help. But remember: "indent" is not a panacea style of poor procedures.

C language function in the operation of the source code of some string

Many people think that the difficulty is the C language pointer, on the understanding of the pointer is directly related to the programmed program is good or bad, so
Here cited a number of C compilers usually have a standard function of the source code, read them on the pointer and the string can be understood.
1. Strlen (), calculate the length of the string
int strlen (const char string)
(
int i = 0;
while (string) i + +;
return i;
)
2. Strcpy (), string copy.
char * strcpy (char * destination, const char * source)
(
while (* destinaton + + =* source + +);
return (destination-1);
)
3. Strcat (), the connection string.
char * strcat (char * target, const char * source)
(
char * original = target;
while (* target) target + +; / / Find the end of the string
while (* target + + =* source + +);
return (original);
)
4. Streql (), to judge whether two strings are equal.
int streql (char * str1, char * str2)
(
while ((* str1 ==* str2 )&&(* str1))
(
str1 + +;
str2 + +;
)
return ((* str1 == NULL )[$&(* str2 == NULL))]
)
5. Strchr (), find a character in the string.
char * strchr (const char * string, int letter)
(
while ((* string! = letter) & (* string))
string + +;
return (string);
)
6. Chrcnt (), a character in the string calculation of the number of occurrences.
int chrcnt (const char * string, int letter)
(
int count = 0;
while (* string)
if (* string == letter) count + +;
return count;
)
7. Strcmp (), to judge whether two strings are equal.
int strcmp (const char * str1, const char * str2)
(
while ((* str1 ==* str2 )&&(* str1))
(
str1 + +;
str2 + +;
)
if ((* str1 ==* str2 )&&(!* str1)) / / Same strings
return o;
else if ((* str1 )&&(!* str2)) / / Same but str1 longer
return -1;
else if ((* str2 )&&(!* str1)) / / Same but str2 longer
else
return ((* str1> * str2)? -1:1);
)


Function pointer and function of the difference between reference

C + + function pointers is one of the biggest advantages. And compared using ordinary pointers, senior programmer as long as there are probably more willing to use the reference because it easier to deal with some references. However, when dealing with function, function pointer on the reference comparison function may not have this advantage. Existing code is rarely used function reference.

In this article, we will show you how to function pointers, how to use the function reference, and under what circumstances were to use them.

Here are some examples of function pointers:

# Include <iostream>

void print (inti)
(Std:: cout <<i <<std:: endl;)

void print_2 (inti)
(Std:: cout <<i <<std:: endl;)

void multiply (int & nDest, intnBy)
(NDest *= nBy;)

void print_something ()
(Std:: cout <<"something" <<std:: endl;)

int return_1 ()
(Return 1;)

int main ()
(
void (* func_1) (int);
func_1 = [$ print]
func_1 (1);
/ / Or, we call it this way
/ / (Because it is a pointer, so it can re-quote)
(* Func_1) (1);
func_1 = [$ print_2]
func_1 (1);

void (* func_2) (int) = [$ print_2]
func_2 (1);

void (* func_3) (int [$, int) = & multiply]
inti = 1;
std:: cout <<"[before] i =" <<i <<std:: endl;
(* Func_3) (i, 10);
std:: cout <<"[after] i =" <<i <<std:: endl;

void (* func_4) ();
func_4 = [$ print_something]
func_4 ();

int (* func_5) ();

/ / Note: Some compilers allow you to write
/ / "Func_5 = return_1;" (ie ignore'&');
/ / However, we do not recommend such an approach;
/ / The following uses will reveal this fact:
/ / 'Func_5' is a pointer, if you ignore the '&'
/ / Code is not clear on the meaning of
func_5 = [$ return_1]
std:: cout <<(* func_5) () <<std:: endl;

std:: cin.get ();
return 0;
)

Here are some examples of function references:

/ / Print, print_2, multiply, print_something, return_1
/ / Other functions and the same as above.

int main ()
(
/ / Error: uninitialized reference!
/ / Void ([$ func_1) (int)]

void ([$ func_1) (int) = print]
func_1 (1);

/ / Error: can not assign to the reference!
/ / Func_1 = [$ print_2]

void ([$ func_2) (int) = print_2]
func_2 (1);

void ([$ func_3) (int &, int) = multiply]
inti = 1;
std:: cout <<"[before] i =" <<i <<std:: endl;
func_3 (i, 10);
std:: cout <<"[after] i =" <<i <<std:: endl;

void ([$ func_4) () = print_something]
func_4 ();

int ([$ func_5) () = return_1]
std:: cout <<func_5 () <<std:: endl;

std:: cin.get ();
return 0;
)

As the existing code usually use a function pointer, so we suggest you follow this practice. We like to use function pointers Another reason is its consistency, in addition to pointer to a function, you also can point to a member function pointers.

Function reference can be used as function parameters to use, it means the same value. For example:

# Include <iostream>

void print (inti)
(Std:: cout <<i <<std:: endl;)

void print_2 (inti)
(Std:: cout <<i * 2 <<std:: endl;)

void call_func (void (& func) (int))
(
/ / The following line will cause error occurred:
/ / (If the function passed as a pointer,
/ / This may be correct)
/ / Func = print_2;

func (1);
func (2);
func (3);
)

int main ()
(
call_func (print);
call_func (print_2);
std:: cin.get ();
return 0;
)

Create a type pointing to const function pointer is difficult; If the function reference, it had the characteristics of the natural.

Control C + + memory allocation

Used in embedded systems C + + A common problem is the memory allocation, ie new and delete operators out of control.

Ironically, the root of the problem is that C + + memory management is easy and safe. Specifically, when an object is eliminated, its destructor to secure the release of the allocated memory.

This is of course a good thing, but this simply makes use of the excessive use of new programmers and delete, without attention to the Embedded C + + environment causation. And, in embedded systems, due to memory constraints, frequent memory dynamically allocated variable size will cause a huge problem and the risk of heap fragmentation.

As a warning, the conservative use of memory allocation is the first principle of the embedded environment.

But when you have to use new and delete, you have to control the C + +, memory allocation. You need to use a global new and delete instead of system memory allocation operator, and a class of a class of overloaded new and delete.

A common way to prevent heap fragmentation is different from fixed-size memory support in the distribution of different types of objects. For each class overloaded new and delete on the provision of such control.

The new and delete overloading the global operator can easily override new and delete operators as follows:

void * operator new (size_t size)
(
void * p = malloc (size);
return (p);
)
void operator delete (void * p);
(
free (p);
)

This code can replace the default memory allocation operators to satisfy the request. C + + for the purpose of explanation, we can call malloc () and free ().

For a single class of new and delete operator overloading

Can also be a single class of new and delete operator overloading. This is your flexibility to control the object's memory allocation.

class TestClass (
public:
void * operator new (size_t size);
void operator delete (void * p);
/ / .. Other members here ...
);

void * TestClass:: operator new (size_t size)
(
void * p = malloc (size); / / Replace this with alternative allocator
return (p);
)
void TestClass:: operator delete (void * p)
(
free (p); / / Replace this with alternative de-allocator
)

All TestClass object memory allocation code are used. Further, any inherited from class TestClass also use this approach, unless it itself and delete overloading the new operator. By overloading operator new and delete methods, you are free to adopt different allocation strategy, memory pool allocation from different objects in different classes.

For a single class overloaded new [] and delete []
The allocation of an array of objects to be careful. You may wish to call to be off your overloaded new and delete operators, but not so. Memory request is directed to the overall new [] and delete [] operator, and these memory from the system heap.

C + + memory allocation object array as a separate operation, but different from the single object of memory allocation. In order to change this way, you also need to overload new [] and delete [] operator.

class TestClass (
public:
void * operator new [] (size_t size);
void operator delete [] (void * p);
/ / .. Other members here ..
);
void * TestClass:: operator new [] (size_t size)
(
void * p = malloc (size);
return (p);
)
void TestClass:: operator delete [] (void * p)
(
free (p);
)
int main (void)
(
TestClass * p = new TestClass [10];

/ / ... Etc ...

delete [] p;
)

But note: for most C + + implementation, new [] operator in the number of parameters is the size of the array with the extra number of bytes stored in the number of objects. Memory allocation mechanism in your consideration of this important point. You should try to avoid distribution of an array of objects, so that your memory allocation strategy is simple.

Learn about the three C + + stored

C + + has three stores: automatic storage mode, static mode and the free storage memory means. Each object is stored has a different method of initialization and living space. In the following paragraphs we will elaborate the three storage methods differ, and to show you how to effectively and safely use them.

Automatically stored

Usually, we do not object to define local static or external, but it is defined as the automatic and register. Function arguments are automatically stored, this storage method is called stack memory. The following examples include a variety of ways a statement object, automatically stored in various forms.

/ / S 'storage type s is determined by the caller
void f (const std:: string [$ s)]

/ / Arguments passed by value are automatic
void g (register int n);

int main ()
(
int n; / / automatic because local, non-static, non-extern
register inti; / / register implies automatic
auto double d; / / auto implies automatic
g (n); / / passing a copy of n; the copy is automatic
std:: string s;
f (std:: string temp ()); / / a temp object is also automatic
)

Automatic objects are usually based on a function or a block, when the function or block the end of the automatic object is immediately destroyed. Thus, when it entered each time a function or a block of time, the object will automatically create a new setting, automatic variables, and no class object's default value is uncertain.

Static storage mode

Global object, a class of static data members and functions of the static variables are static storage areas. The memory address of a static object in the entire run of the process is the same. Living space in a program, each static object is constructed only once.

The default value of static data is initialized to binary zero, the static object with non-void constructor (constructor by the compiler or C + + implementation) is initialized immediately. The following example shows how to store static objects.

int num; / / global variables have static storage
static int sum; / / so do static objects declared globally
intfunc ()
(
static int calls; / / initialized to 0 by default
return + + calls;
)

class C
(
private:
static bool b;
);

namespace NS
(
std:: stringstr; / / str has static storage
)

Free storage mode

Free storage, also known as the heap storage (in the C li) or dynamic storage, which includes the program code to generate the necessary manipulation to new objects and variables. Objects and variables will continue to allocate storage space, call the delete operation until they are released.

Call Remove Programs failure will lead to memory, call the structure function analysis of the results of failure is unpredictable, with the object of automatic and static compared to the free storage address the object at run time has been identified. The following example shows the process of automatic storage object.

int * p = new in t;
char * s = new char [1024];
Shape * ps = new Triangle;
/ / S 'storage type s is determined by the caller
void f (const std:: string [$ s)]
std:: string * pstr = new std:: string
f (pstr);
delete p;
delete [] s; / / s is an array
delete ps; / / invokes the destructor
delete pstr; / / ditto

C + + to learn the Way - constructor and destructor

Class constructor is generated automatically called when an object class, which is used to initialize the object's data members. Class destructor is added before the class name "~" as the function name of function, it is automatically deleted when the object is called, that program execution leaves the scope of class object initialization call. Destructor does not actually delete the object itself, but for system memory before giving up the clean-up work, so the memory can be used to save the new object.
Constructor and destructor is automatically called, and they call the order depends on the implementation of the order of entering and leaving the object. We come to give specific examples to illustrate the order of their call.

/ / Create.h
# Ifndef CREATE_H
# Define CREATE_H

class CreateAndDestroy (
public:
CreateAndDestroy (int); / / Constructor
~ CreateAndDestroy (); / / destructor
private:
int data;
);

# Endif

/ / Ceate.cpp
# Include <iostream.h>
# Include "create.h"

CreateAndDestroy:: CreateAndDestroy (int value)
(
data = value;
cout <<"object" <<data <<"a";
)

CreateAndDestroy:: ~ CreateAndDestroy ()
(
cout <<"Object" <<data <<"destructor" <<endl;
)

/ / Create1.h
# Include <iostream.h>
# Include "create.h"

void create (void);

CreateAndDestroy first (1); / / global object

int main ()
(
cout <<"(before the establishment of global objects in the main)" <<endl;
CreateAndDestroy second (2); / / local object
cout <<"(local automatic object in the main function of the internal build) <<endl;

static CreateAndDestroy third (3); / / local object
cout <<"(local static objects in the main to create)" <<endl;

create (); / / Call create () to establish object

CreateAndDestroy fourth (4); / / local object
cout <<"(local automatic object creation)" <<endl;
return 0;
)

void create (void)
(
CreateAndDestroy fifth (5);
cout <<"(local automatic object in create () to create)" <<endl;

static CreateAndDestroy sixth (6);
cout <<"(local static object in the create () to create)" <<endl;

CreateAndDestroy seventh (7);
cout <<"(local automatic object in create () to create)" <<endl;
)

Fourth and the second object destructor when reaching the main end of one call. As the third is the static local objects, so that when the exit end of the process, the program terminates after the object and remove all the ** destructor is called first before the third call the object destructor. Function create three objects a statement. Fifth and seventh object is a local automatic object, the object sixth is the static local object. Object seventh and fifth in the destructor is automatically called when the end arrived create. As the sixth object is static local objects, so that when the exit end of the process. sixth destructor to delete the program termination after all ** the object and the third and the first call to the function called before the new structure.

C + + did not sleep at night ---- I am learning C + + thought process

Some posts have been because they caused everyone in the online C + + to learn and use the discussion to return to remember their contact with C + + more than three years, a year ago, to learn courage to start the scene again, now my heart several more feeling, more of a learning process feel quite universal, tried several times to write down some of their own experiences, to conclude and be on their own review, let alone help others even if I believe it can be a learning C + +, Case study it. But the first few times pick up a pen is always a perfectionist, wanted to write everything down, but after a few pick up a pen and a few give up, I finally give up the "perfect" idea, a moment still, and their female Friends call this an hour, count the number of how many can say it, after all I said was written down out.

Contact C + + is 99 years, at that time that they have some C-based, and has just started will use the keywords than C it may be just more of the Class it, that time in school, but also learn VC + +, write Several very Jian Dan's games, and then because a lot of trivia not Zai Zai C + + on You more of Shen Ru, which I very much regret the Shi Qing Xian Zai, Ye Xu that time I can allocate into, and it is quite small Neng Cheng Liao .

In 2002 started a new course, I have enough to spend your time. In that year's summer vacation, starting a new C + + to learn, I know I have the basis for learning C + + is almost not there any more help, so I chose to start again from the IF .... ELSE so grammar start. Select the first book friends friendship gift "C + + PRIMER", then I just read less than three days, I do not have to read, I know that this book is very good, but definitely not for me at the time, because from the beginning what had me confused too, classes, templates, overloading ... ..., this thing almost made me give up learning C + +, because I felt that time had a certain skill C, and put out through the C For me that time is a good choice, but after all, the content C can not I have more passion, repeating things I've never liked. Then I began to consider + + The only marked difference between the two languages implies something in the end? At the same time I began to consider what programming language in the end? Then I borrowed the book in the library "programming language concepts and implementation", regardless of how others think of this book, but it made me understand a lot, because most of the features of this book is the abstract of a modern programming language which contains a variety of semantics and the idea of language itself that I have a more profound understanding of the concept, let me build to a variety of language itself represents a different syntax to achieve a total of all languages for the semantic, The semantics of a logical series has reflected a more general program design. In With this in mind, I come into contact with a "C + + Design and Evolution" This book in learning C + + process in this book helped me is the biggest, this book made me understand C + + design concepts and various Language facilities represent the realization of the semantic, not only a myriad of C + + language features are aimed at achieving a functional and without violating the basic C + + design philosophy built on. This for C + + macro basis, let me in later study days greatly benefit from, and "C + + Design and Evolution" This book I also have in both versions, when I was a lot about C + + features confused when I will put English (casually show off, this book has BS autograph:)) out, and then Haohao Di look. Like a while back for the C + +, Learning, indeed discussed a lot, so I have this book out again to assess their point of view held is correct. Since then, I think I be learning C + + into the correct path.

BS came to China in October, that time I have C + + can be said that only a complete beginner (Oh, give you an example, that when I met in Hangzhou cber, he began to tell me his screen name, I said you What is the name? later he wrote his name and contact information I do not know I was standing opposite the C + + top players, thanks to that time I have a picture of a picture with him, I suppose I wiser place it at least left no regrets.) Although I am a beginner, but I do not think I should not miss this master of close contacts and opportunities (particularly in repeatedly read through most of his books and papers later), at their own expense to to Hangzhou (in fact, where the students also spent a lot of money:)) listening to BS in Zhejiang University's report, I went early, sat in the first row, the entire report is also my first questions, and remember that time My question was how naive, but I told myself no matter how kind their own now, this opportunity may not have a life, so I always keep a very positive, BS very detailed response to the back as well and I leave for basic in listen to state: "But the BS of the master's touch made me upside down, from the study for the C + + I have not utilitarian.

Learning is the accumulation, during which I read "C + + programming ideas", but also on the C + + have a more emotional understanding, three months after the re-out "C + + PIRMER", this time I have been able to fully understand LIPPMAN this classic masterpiece of ingenious heart, and it is definitely not for beginners to see, but for entry entirely after the study and understanding of C + + effect is obvious, from the book the start straight into C + +, theme, the previous five chapters Du Using Class 1 data structure Let the reader fully understand the various user-defined types represented by the abstract ability, then go directly to Chapter VI of the standard library container class, this design allows the reader to establish a very clear class container and two C + +, a very important concept , after the study is also very rewarding. Previous programming experience learn to tell me, writing is the learning center program, and therefore I "C + + PRIMER" Most of the code through debugging, and sample code consistency is the biggest feature of this book, but The other big feature is not a code can be directly, and all need their own debugging the debug such code Guocheng in deepened my understanding of more than C + +. Less than two months of the time it "C + + PRIMER" first read it again, plus the top and everyone in exchange CSDN feeling has been established for the complete C + +, basic understanding.

Have not read "C + + programming language" is the C + + you learned? In my eyes, if even the language of the creator of the book have not read, how to understand this language? Last year in December I spent a whole month reading this book Haohao Di twice, the only feeling is that this book is really qualified to be called "C + + programming ideas". Book and "C + + PRIMER" is completely different styles, which tell you is a complete C + + syntax and semantics of their support. The former is really tell you how to think in C + +, and prepared in accordance with C + + design code. You can see the C + +, great design ideas under the concept of program design and coding specifications. New Year's Day this year, compared to the original feel no progress is already small, so do not continue reading, but in the winter saw several large point size of the C + + program source code.

After that, I also read a number of C + + all the work here need to make to the "C + + Standard Library" and "C + + meditation", the former way of writing easy to understand, but the book content is very rich, for learning the standard library It can be said is the best performance of work. The latter, read feel and "C + + programming language" as a very strong ideology, reading this book very tired, my mind must have been thinking, thinking of the issues raised and which he put forward solutions. The greatest feature of this book is very direct to the core C + + languages exposed ----- three kinds of abstract models and very language of the facilities themselves to support these three abstract models. The "C + + meditation" Give me deeper thinking is what is the use of C + + the most reasonable way, then I posted this is to explain their learning for the C + + and use some of the insights of the original source of thought.

Still later, his slowly with C + + to achieve a number of small programs, some books, and some are their own thinking and writing process and the process of debugging my feeling is that the alternating process of trouble and meet is probably the way the process is repeated programmers sought. The article now, most of recorded history of their own, for many readers here, I believe that did not help, the following to say I very direct their own learning C + + experience, from my experience in front of all of us can look out of my not a master, but I guarantee that I am about to write something for the novice C + + is very helpful, after all, I just passed it a dark day when.

Learning C + + language facilities to understand its emphasis represented by semantic, and C + + can represent the semantics of that design. First of all, starting from the macro level, you need to understand is that C + + programming language is essential. Here I put C + + to write down the most important properties: C + + is a static type checking, memory mode based on C, supports four basic paradigm programming language. Note here that three essential characteristics, static type checking described the nature of language, based on the C memory model tells us that C + +, all memory-related operations are required to be responsible for their own programmers, so that brought a lot of the design process Note that local time, while the understanding and support of the four basic paradigm is to understand the basis of language facilities. Then remember C + +, most point design philosophy, is its cross-cutting application of C + +, an essential, and I quote "C + + PRIMER" Chinese Foreword to the phrase that - "C + + is based on a variety of facilities, which allow users to define new data types to extend the language itself, these new types of the same type can be used with the built-in way (how to understand this sentence is the key, my understanding is: the user-defined types may at any time using the built-in type as The alternative, more specific point that is user-defined types can be done as built-in type can be declared, the object can be initialized, you can copy each other, like a built-in types of objects can be done and a lot of operators, the system can be used as Parameters passed to the function, can be used as function return values, can be used as the operation of the container object, user-defined types can be built the same type as the template parameter), control of these facilities (which facilities? is to allow user-defined types can be built convenient to use the same type of facilities, including what? structure, copy, deconstruction function, operation overloading .....) deputy first step to understand the basic language (what is the basic language? is the C + +, better c section).

Here, I would like to point out a very important concept: a language of the most essential thing is its type system, any language has its own unique type of system, learning C + + is learning his type system. So, first need to thoroughly understand what the concept of data type. This will clear your thinking, you have chosen, from each of the design of C + + support to start learning paradigm.

----- Structural design that is C + + in the better c section, you need to learn the basis of the C function overloading and reference the language of the two most important new special Mind.

---- Based on the object you need to build the most powerful C + + concepts - class, that is user-defined type, which is actually inside the contact data structure the concept of abstract data types, and the reasonable use of the class constructed a series of language measures. And always keep in mind when designing C + + classes that we need to use that concept. C + + abstract class mechanism is inside the core concept.

Object-Oriented ---- where you need to know the inheritance and polymorphism concepts such as OO, and handle such common design class, where you need to know that you entered the stage of interface programming. At the same time thinking you want to learn OO, C + + some of the facilities only to the OO ideas in language that is supported by the semantic representation of them in full. But here, and you need to understand C + + to express the semantics is the principle by its original language design constraints (what principle? Static type checking, do not pay for the things that do not need, to choose the language itself is not in the hands of the programmer to force the programmer to make a choice), that C + + OO ideas can be expressed as a C + + features of OO thinking of. Such ideas and JAVA OO represent pure OO which is better? No conclusion, because they are not the same design concept.

Generic Design ---- Here you need to understand the most important point is that C + +, temlate mechanism, regardless of what was originally conceived as the beginning, and now he represents the true meaning is: compile-time type inference, that is, compile-time polymorphism, the The generic core --- understood as an abstract condition of the various types of concrete, C + + there are measures you can define abstract terms? Not, so these conditions can only be defined in our own hearts, but we can put specific terms of the type as an abstract mechanism to achieve in the template, so tempalte be further than the type inference mechanism to something that is Derivation of abstract terms. That is, we no longer accept the parameters as a template type, but the template as a condition of acceptance of abstract mechanisms, regardless of its type to, as long as this type of abstraction to meet tempalte accepted the conditions can be as a parameter in, so that represents a generic type is no longer thought ----- fundamental condition is the abstract, the type is abstract terms, but the cloak and in the C + + in the realization of ways. Based on the combination of the two objects and the generic design of the abstract design pattern is technically the birth of industrial products --- STL.

** Besides the idea of the final point, C + + as a design model to support a variety of computer programming language, its implication is a profound thought, mastery is not easy, it is impossible and proficient, but as the beginning design of C + + So, you know C + + is not the place does not prevent you from using the C + + and C + +, within the limits you to make reasonable design. But we should understand that to a certain extent, when we should jump out, stand in a higher place to re-examine the C + +, to re-examine their own language for the program, for design ideas, and even understanding of the nature of software is in continuous progress ? For C + + to serve others can not be ignored ** excuse to master the technology, in short, face the music from the new things we have our own judgments, too flashy is a shame that we have, but in the path of growth and must can not afford to do frogs.

C + + programming skills

1:
C + + program should be simple and direct approach to the preparation, known as KIS ("keep it simple", keep it simple), do not use the method is not used any of the expansion process
2:
Each piece of program should note statement at the beginning, describing the purpose of the program!

For example:
/ / OUR FIRST PROGRAM "Hello"

# Include <iostream.h>

int main ()
(
cout <<"Hello! C + +";

return 0;
)
3:
Can declare a variable line only, so you can insert comment statements of each statement.
4:
In each "," followed by a space, make the program more readable.
For example:
int a, b, c; than int a, b, c; easy to read.
5:
Select meaningful variable names can process more clearly.
6:
Avoid the use of underscores and double underscores at the beginning of the identifier, a C + + internal use of such names.
7:
Executable statements and statement of line space left between the best, so make a statement more clearly, the program more clearly.
8:
Placed on both sides of the dual operator spaces, operators can more obvious, the program easier to read.
9:
In expression with extra parentheses make the code more clear, these brackets become redundant parentheses.
10:
if statement can be indented to improve readability, outstanding structure.
For example:
if (n1 <n2)
n1 = n2;

if (n1 <n3)
n1 = n3;
11:
Program only put one line statement.
12:
Long statements can be divided into multiple lines. If a statement can be divided into multiple lines, can be a comma delimited list or a long expression operator behind the line break.
For example:
int num [10] = (0, 1, 2, 3, 4,
5, 6, 7, 8, 9);

total = num [0] + num [1] + num [2] + num [3] + num [4] +
num [5] + num [6] + num [7] + num [8] + num [9];
13:
If you can not determine the expression evaluation order of evaluation, you can use parentheses force the order.
14:
Throughout the process, insist on a reasonable indentation rules can greatly improve the readability, the proposed emission reduction by three spaces.
15:
Must initialize the counter and the sum of variables.
16:
Do not compare floating point values of equality and the unequal nature, and to test whether the difference absolute value is less than the specified value.
17:
In a statement, the variable initialization data is not the initial problem can be avoided.
18:
Unary operator and its operands can not insert a space between.
19:
Numerical control with the whole count cycle.
20:
Indent each control structure in the statement.
For example:
for (int i = 0; i <10; i + +)
total = total + num;
21:
Before and after each control structure with an empty line, so clear in the program.
22:
Too much will make it difficult to understand the nested procedures. In general, indentation No more than 3 layers.
23:
Switch structure should provide default case.
24:
Despite the return value is omitted, type defaults to int, but the best explicitly specify the return type.
25:
Passed to the function parameters and function definitions in the corresponding parameters can be the same name, but do not with the same name in order to avoid differences.
26:
Choose a meaningful function names and parameters meaningful names to avoid heavy use of annotation statement.
27:
Avoid the inner and outer block use the same identifier, so as not to block the outer range of variables to be hidden.
28:
inline (inline function) qualifier often used only for small functions.
29:
The length of each array is defined as the constant variable instead of constant, can process more clearly and make it more scalable.
For example:
const int a = 5;
int num [a] = (0, 1, 2, 3, 4);
30:
Efforts to ensure the procedures are clear, and sometimes can even do this at the expense of performance.
31:
Including the parameters in the function prototype in the name can make the program clear, but the compiler ignores the name.
32:
Subscript will be used to double the first subscript array that line, the second subscript that out.
33:
Parameter table in the function prototype, the more the first subscript subscript array length is not required, but then under the standard length of all long required.
34:
Although not necessary, but add in the pointer variable ptr more clearly indicates that these variables are pointers.
For example:
int * countptr;
35:
Passing arrays to functions at the same time passing the array length (rather than the length of the function to create an array of information), make the function more general, in order to be reused in many programs.
For example:
const int size = 5;
int num [size] = (0, 1, 2, 3, 4);

print (num, size);
36:
Pointer arithmetic is only meaningful when in the array.
37:
Array operations instead of using array notation to pointer notation program clearer.
38:
Character strings stored in an array, we must guarantee that it will save enough to keep the maximum string or an array of cross-border character will overwrite the back of the data stored in the memory address.
39:
Each member access specifier used only once in the class definition. The sample can increase the clarity and readability, the members of the public on the front, easy to find.
For example:
class Time (
public:
Time ();
void setTime (int, int, int);
void printTime ();
private:
int hour;
int minute;
int second;
)
40:
While public and private labeling can be repeated and mixed, but the best first fitted to all public members of a group, and then fitted to a group of private members, so that customers can focus on the class public interface, rather than the class Implementation.
41:
Generally required to provide a constructor, to ensure the right of each object is initialized to meaningful values. In particular, the pointer data type, the pointer should be initialized to the legal or 0.
42:
Do not let the class public member function to return to the class private data members of non-const reference (or pointer), to return such a reference would undermine the kind of package.
43:
To all the friend class declaration on the relationship between the first class, do not add any member of its front access specifiers.

C language, common errors

C language is the biggest characteristic: strong functions, convenient and flexible. C compiled program on the grammar check is not as strict as other high-level language, which gives programmers left "room for flexibility", but still flexible as to the process of debugging this brought a lot of inconvenience, especially for beginners C language people, some with their own often do not know went wrong mistakes. Look at the procedure wrong, I do not know how to change since I passed on the C of the study, accumulated some C programming mistakes from time to time, addressed to the participants for reference.
1. Writing an identifier, it neglected the difference between uppercase and lowercase letters.
main ()
(
int a = 5;
printf ("% d", A);
)
Compiler that the a and A are two different variable names, and display an error message. C uppercase and lowercase letters that are two different characters. Traditionally, symbolic constant names in uppercase, the variable name in lower case, said in order to increase readability.
2. Ignores the variable type, carried out illegal operations.
main ()
(
float a, b;
printf ("% d", a% b);
)
% Is to request the operation, get the a / b of the entire balance. Integer variables a and b can be to request the operation, while real variables are not allowed to "demand more than" operator.
3. The character string constant with the constant confusion. char c;
c = "a";
Here is confusion in the character constants and string constants, character constants by a pair of single quotation marks a single character string constant is a pair of two-character sequence enclosed in quotation marks. C provides a "\" as string end marker, it is automatically added by the system, so the string "a" actually contains two characters: 'a' and '\', and assign it to a character variable not work.
4. Ignore the "=" and "==" distinction.
In many high-level languages, use the "=" sign as a relational operators "equal." If the program can be written in BASIC
if (a = 3) then ...
But C, "=" is the assignment operator ,"==" is relational operators. Such as:
if (a == 3) a = b;
The former is compared, a and 3 are equal, which means that if a and 3 are equal, the b value is assigned to a. As a matter of habit, beginners tend to make such a mistake.
5. Forget the semicolon.
Semicolon is C an integral part of the statement, the statement must have a semicolon at the end.
a = 1
b = 2
Compile time, compiler in "a = 1" did not find the back of the semicolon, put the next line "b = 2" is also on the line as part of statement, this syntax error occurs. Error correction, sometimes in the wrong line to be pointed out that were not found error, you need to look at whether the missing semicolon on the line.
(Z = x + y;
t = z/100;
printf ("% f", t);
)
For the compound statement, the last statement can not be ignored the last semicolon write (this is different, and PASCAL).
6. More semicolon.
For a compound statement, such as:
(Z = x + y;
t = z/100;
printf ("% f", t);
);
Compound statement should not add a semicolon after braces, it will be superfluous.
Another example:
if (a% 3 == 0);
I + +;
This is, if 3 divides a, then I add 1. However, if (a% 3 == 0) later added a semicolon, the if statement to this end, the program will perform the I + + statements, whether 3 is divisible by a, I will automatically add a.
Another example:
for (I = 0; I <5; I + +);
(Scanf ("% d", [$ x)]
printf ("% d", x);)
Purported to have input 5 numbers, each number and then enter an export it. As for () to add a semicolon after, so that loop into an empty statement, this time can only enter a number and output it.
7. Input Variable
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of [Change] secondary school students in the C + + the way!

  • hibernate call stored procedure

    hibernate call stored procedure

  • hibernate using c3p0 connection pooling

    Private http://www.lifevv.com/tenyo/doc/20070605102040991.html c3p0 for open source's JDBC connection pool, with the release hibernate. This article describes how to use the hibernate configuration in c3p0. c3p0 connection pool configuration is v ...

  • Hibernate configuration parameters hibernate.hbm2ddl.auto

    Hibernate in the configuration file: <properties> <property name="hibernate.hbm2ddl.auto" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...

  • [Reprint] Java professionals required books and list of sites

    Concurrent Programming in Java: Design Principles and Patterns (Doug Lea) Concurrent Programming in Java: Design Principles and Patterns, 2nd edition (Doug Lea; Addison-Wesley, 1999 years) Java Concurrent Programming - Design principles and patterns (seco

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries