Understanding-and-Using-C-pointers

#### Why You Should Become Proficient with Pointers

Several uses of pointers:

* Creating fast and efficient code
* Providing a convenient means for addressing many types of problems
* Supporting dynamic memory allocation
* Making expressions compact and succinct
* Providing the ability to pass data structures by pointer without incurring a large overhead
* Protecting data passed as a parameter to a function

Several possible problems with pointers:

* Accessing arrays and other data structures out of bounds
* Referencing automatic variables that are already good
* Referencing heap memory after the contents are freed
* Dereferencing the pointer before the memory is allocated

The syntax and semantics of pointers are defined by the C specification, but there are cases in which the definition is not explicitly defined, in which case the behavior is defined as:

* Implementation-defined
* Unspecified
* Undefined

#### Declaring Pointers

#### How to Read a Declaration

**The trick is to read them backward.**

#### Address of Operator

good practice: initialize a pointer as soon as possible

#### The Concept of Null

Several Nulls:

* The null concept
* The null pointer constant
* The NULL macro
* The ASCII NUL
* A null string
* The null statement

When NULL is assigned to a pointer, it means that the pointer does not point to anything.

A null pointer is not the same as an uninitialized pointer: the latter may contain any value, and the former does not point to any memory location.

#### To NULL or not to NULL

The meaning of zero changes with context.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325943753&siteId=291194637