JNI-C Pointer Syntax
When I looked at Ali's hot repair code recently, I found that it was basically processed at the C layer. I thought that I had taken the C2 certificate before, and I still knew the basics of the C language. I didn't expect to see a lot of *& symbols. Remember that the * symbol is used for pointers. As for how pointers are used, I can hardly remember. I thought that if you want to be proficient in JNI, you must first be proficient in c pointers, so let’s review the pointers in C syntax
In order to learn c syntax, an eclipse c++ version is installed first, and then minGW is installed to configure its environment. You can easily learn c in it like learning java .
Configuration tutorial : http://blog.csdn.net/sunny2038/article/details/6918602
Be sure to rename mingw32-make.exe to make.exe
Be sure to rename mingw32-make.exe to make.exe
Be sure to rename mingw32-make.exe to make.exe
The important thing is said three times, even if I didn't pay attention to this, I did n't find the mingw configuration in eclipse for a long time
Start your learning journey
pointer
Each variable has a memory location, and each memory location defines an address that can be accessed using the hyphen ( &) operator, which represents an address in memory. Take a look at the example below, which will output the address of the variable defined:
What is a pointer?
A pointer is a variable whose value is the address of another variable, that is, the direct address of a memory location. 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 a pointer variable declaration is:
Here, type is the base type of the pointer, which must be a valid C++ data type, and var-name is the name of the pointer variable. The asterisk * used to declare a pointer is the same as the asterisk used in multiplication. However, in this statement, the asterisk is used to specify that a variable is a pointer. The following are valid pointer declarations:
Example
output
Looking at the print log, you can see that p stores the memory address, which is similar to the toString method of the direct object in java . If the toString method is not overridden , the memory address of the object is also printed. It's just that there is no way to directly print the address of the int type in java . The function of the memory address is to manipulate the value pointed to by the memory address , so it seems that the basic data type does not have much effect on its built-in address .
Arithmetic operations on pointers
A pointer is an address represented by a numerical value. Therefore, you can perform arithmetic operations on pointers. Four arithmetic operations can be performed on pointers: ++, --, +, -.
Assuming that ptr is an integer pointer to address 1000, a 32-bit integer, let's perform the following arithmetic operations on the pointer:
After performing the above operation, ptr will point to position 1004, because each time ptr is incremented, it will point to the next integer position, which is 4 bytes backward from the current position. This operation moves the pointer to the next memory location without affecting the actual value in the memory location. If ptr points to a character at address 1000, the above operation will cause the pointer to point to position 1001, since the next character position is at 1001.
increment a pointer
We like to use pointers instead of arrays in our programs because variable pointers can be incremented and arrays cannot because arrays are a constant pointer. The following program increments the variable pointer so that each element in the array is accessed sequentially:
It can be seen that the array variable name is also a pointer
C++ pointer array
C++ pointer to pointer (multilevel indirection)
pass pointer to function
return pointer from function
untyped pointer void*
Untyped pointers are somewhat similar to Object objects in Java . All pointers can be converted to untyped pointers, and untyped pointers can also be converted to other types of pointers.
function pointer
A function pointer is a pointer variable that points to a function.
Usually we say that a pointer variable points to a variable such as an integer, character or array, while a function pointer points to a function.
Function pointers can be used to call functions and pass parameters just like normal functions.
Declaration of function pointer variable:
Refer to the learning and use of untyped pointer void* on the website : http://blog.csdn.net/playboy_lei/article/details/50560786
Reference URL C tutorial http://www.runoob.com/cplusplus/cpp-pointers.html