16.5 null pointer
Remember how you can specify a character or string as null? If you don't remember, look here. A null character in a string represents the end of a string, but if a pointer is assigned to a null pointer, it does not point to
★Similarities:1. All are addresses;The Pointer Points to a piece of memory, whose content refers to the address of the memory, and the reference is the alias of a piece of memory.
★Differences:1. the pointer is an entity, and the reference is
No so-called null reference:
If a variable may represent an object or no object, Use Pointer;
If this variable must represent an object and cannot be null, you should use reference.
Therefore,The reference must be initialized.But pointer
Today, we can see the C ++ pointer. By the way, let's look at the difference between the pointer and the reference ..
1. First, the reference must be initialized, And the pointer does not have. So if you use a variable and point it to an object,
Pointers If you have experience with c,c++ or Objective-c languages, you may know that these languages use pointers to refer to addresses in memory. A Swift constant or variable referring to an instance of a reference type is similar to a pointer in
Test.cpp: Defines the entry point of the console application.
//
#include "stdafx.h"
#include
#include
using namespace std;
struct A
{public
:
int num;
};
Std::vector nums;
BOOL Modify1 (a& a)
{
//a = B;
A = Nums[0];
return true;
}
BOOL
The three ways to define a pointer are: 1 int * p; 2. int* p; 3. int *p; The habit is different.The three ways to define a function pointer are: 1. int *p (); 2. int * p (); 3. int* p ();
1. Pointer passing and reference passing
In C, if you want
And about the value of delivery, pointer passing, reference transmission in these areas there will be misunderstandings, all I feel the need here also explain ~
Pointers are the same points and different points as references:
★ The same point:1.
C + + offers several different containers for us to choose from, and here's a quick recap:1. Standard STL sequence container: Vector, String, deque, and list.2. Standard STL Associative containers: Set, Multiset, map, and Multimap.3, non-standard
To understand the difference between value passing, pointer passing, and reference passing, the main purpose is to understand the arguments and parameters of the function, the scope of the function (automatic variables, stacks), the layout of the
Original link: http://www.cnblogs.com/yanlingyin/Value Passing :The parameter is a copy of the argument, and changing the value of the parameter does not affect the value of the external argument. From the point of view of the called function, the
First, the conceptValue passing:The parameter is a copy of the argument, and changing the value of the parameter does not affect the value of the external argument. From the point of view of the called function, the value pass is one-way
Tag: Operation returns TOR tool processing source Address object calling function resRecently wrote several deep-seated articles on arrays and pointers, which referred to "C, where all non-array formal parameter passes are in value-passed
C + + value delivery, pointer delivery, reference delivery detailed
Recently wrote several in-depth discussion of arrays and pointers to the article, which refers to the "C language, all non-array form parameter passes are all in value transitive"
The difference between pointers to different types is that the pointer type knows what the compiler interprets in memory content and size in a particular address (the address the pointer points to), whereas the void* pointer represents only one
In terms of concept. Essentially, a pointer is a variable that stores the variable address. It is logically independent and can be changed, this includes changes to the address it points to and the data stored in the address it points.
Reference is
Similarities and differences of reference and pointers1. The substance of pointers and referencesSame: All points to the memory address of the variableXOR: pointer is address variable; Reference is address constant2. Pointers and reference memory
This article is reproduced from http://www.cnblogs.com/tracylee/archive/2012/12/04/2801519.htmlThe difference between a reference and a pointer in C + +The difference between pointers to different types is that the pointer type knows what the
A discussion on value passing, pointer passing and reference passing in C + + caused by &*
The problem out of today in writing Leetcode, discuss found in the &* wording, so found some relevant information, and collation as follows.
C Language Section1. Analysis of pointersint (*p) [5] and int *p[5]The former is a pointer to an array that contains 5 elements. The latter is an array with a length of 5, and each element in the array points to an integer variable.int *f (int i,
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.