(C ++ pointer) Notes

Source: Internet
Author: User

========================================================== ==================================

Title: (c ++ pointer) points to note later

Abstract:

Note:

Date: 2010.6.1

Name: Zhu minglei

========================================================== ==================================

(1) For pointer definition, I used to write char * pszMsg;

This writing method is not very good. It looks like char * is a data type. What if I write it like this?

Char * pszMsg, pszInfo; it seems that two char * type variables are defined, that is, pszMsg, and pszInfo are pointers to char objects. In fact, this is not the case. In this way, pszMsg is defined as a pointer, while pszInfo is just a common char variable. So we need to have a good habit in the future and keep it for a long time. The pointer is defined in the form of * with the variable name.

Define a pointer: char * pszMsg;

Define two pointers: char * pszMsg, * pszInfo;

Mixed definition: char * pszMsg, pszInfo;

......

It seems more standard.

(2) initialization is required when defining pointers.

Sometimes the Code seems to be okay, and the compilation is also 0 errors, but it will run and crash as soon as it runs. This is often caused by irrational use of pointers. It is very dangerous to use a pointer without initialization. You know your current two brushes and you cannot control them as you like. Please initialize them as you like. Direct to an object. If the object to be pointed to does not exist, initialize it to 0.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.