C++ strings, character arrays and character pointers (*, **)
Strings + pointers have been used frequently recently. Sometimes I want to get values or copy, and often encounter problems. Let’s summarize them here.
String processing and pointer use
Long term updated version~
1. char usage related
1.1 Memory usage
First, let’s introduce the data types in C language:
The figure below shows the number of bytes occupied by different data types. The storage size of various types is related to the number of system bits, but currently the most common ones are 64-bit systems. The following lists the differences in storage size between 32-bit systems and 64-bit systems (same for Windows):
Pointers are memory addresses, and pointer variables are variables used to store memory addresses. Just like any other variable or constant, you must declare a pointer before using it to store the address of another variable. The general form of pointer variable declaration is:
A pointer is a variable used to store an address. The address uniquely identifies a memory space; the size of the pointer is a fixed 4/8 bytes (32 platform/64 platform).
assigns the string to a character pointer variable p. Instead of assigning the content of the string to pstr, it assigns the address of the first character of the string to pstr.
To print a character, use %c. The address of a is stored in p. *p is a.
Print the entire character and stop when **"\0"** is encountered. Use %s. The address of a is stored in p. Simply put p at the end and print a string starting from the address where p is stored, and "abcdef" will be printed.
But today I encountered a problem with pointer parameter passing. The interface in the C++ encapsulated dll is called through the C++ exe to update the pointer data/image data.