Pointer learning (1)

Based on the previous study of structure arrays, I realized that the pointers were not yet understood until the next step when I understood the structure pointers.

Regarding pointers, we must figure out the concepts of memory and address. In order to clarify the concept of pointers.

Direct access: a=5; (assignment)
indirect access:
such as: scanf("%d",&a); when calling a function, pass the address of variable a to the function scanf, and the function first saves the address in a unit, Then save the data received from the keyboard to a variable through the stored address.

Define a pointer variable: int i_pointer;
If you want to store the address of the integer variable i, you can use the statement:
i_pointer=&i; Note that there is no asterisk here. And the name of the pointer variable is i_pointer
"
" means that this is a pointer variable.

Pointers and pointer variables:

  1. Knowing the address of a variable, you can access the variable through this address. Therefore, the address of the variable is called the "pointer" of the variable.
  2. A special type of variable can be defined in C language. These variables are specially used to store the address of the variable. They are called pointer variables.
    Note
    The value of the pointer variable (that is, the value stored in the pointer variable) is the address (that is, the pointer).

You can use an assignment statement to make a pointer variable get the address of another variable, so that it points to a variable.

When defining a pointer variable, you must specify the base type, and only the integer type points to an integer type such as this.

Only addresses (pointers) can be stored in pointer variables;
*: value symbol
&: address symbol The
two operators have the same priority. From right to left
, the address operator & is provided in the C language to indicate the address of the variable. General form: & variable name;

Simple example:

#include <stdio.h>
int main()
{
    
    
	int a,b;
	int *pointer_1,*pointer_2;
	a=100;b=10;
	pointer_1=&a;
	pointer_2=&b;

	printf("%d,%d\n",a,b);
	printf("%d%,%d\n",*pointer_1,*pointer_2);
}

The concept that pointers give me is: give an address to point to a value. Based on the knowledge of the & and * operators.

Guess you like

Origin blog.csdn.net/yooppa/article/details/112596726