Get the App
SLTechnology News&Howtos  ›  Development  › 

How to define and use pointers in C++

Shulou Source: shulou.com Published: 2022-06-01 17:35:11 09月12日 Update

This article mainly explains "how to define and use pointers in C++". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to define and use pointers in C++".

1 the basic concept of pointer

Function: memory can be accessed indirectly through pointers.

Memory numbers are recorded from 0 and are usually represented by hexadecimal numbers. You can use pointer variables to save addresses.

2 definition and use of pointer variables

Pointer variable definition syntax:

Data type * variable name; & you can take the address; * you can take the value stored by the address

Example:

# includeusing namespace std;int main () {int a = 10; / / 1. Syntax for pointer definition: data type * pointer variable name; int* p; / / int* defines a pointer variable p = & a; cout pointing to an integer type

Tags: Pointers pointers variables constants addresses memory arrays spaces functions that is examples elements functions bytes data types errors sorting clocking characteristics Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple Shulou Tech Info Linux Xiaomi