C pointer when to bring and when not to bring 40

Updated on Car 2024-03-02
22 answers
  1. Anonymous users2024-02-06

    The case with *.

    1.When declaring, you need to use * to indicate that the declared object is a pointer. e.g.: int*p;

    2.When using the value of the pointer. For example: printf("p = %d",*p);

    3.When assigning a value to a pointer. *p = 5;

    Without *:

    1.When using the pointer. For example: int a = 0; p = &a;(p is int*).

  2. Anonymous users2024-02-05

    Classmates: You can't memorize this, you have to understand it.

    The value stored in the memory address indicated by *.

    An absence of * indicates the address of that memory.

    int *p,a;p is the pointer a is an integer.

    int *p,*a;p is a pointer A is also a pointer.

    int *p=&a equivalence int *p; p=&a;

  3. Anonymous users2024-02-04

    If you want to use the content of the pointer, that is, the variable stored in the memory address where the pointer variable is stored, you need to add *. On the other hand, when you need to use the pointer variable itself, that is, this address, you don't need to add *.

  4. Anonymous users2024-02-03

    For example, int *p, which means that p is a pointer to int type, if you want to output the value that the p pointer points to in the function, you need to put * such as a=*p, and without * means to indicate the pointer itself, such as int *p, *p1, p=p1 means that the memory address pointed to by the p1 pointer is assigned to the p pointer, without *

  5. Anonymous users2024-02-02

    The pointer stores the address, and it can be manipulated to point to different data, and when you want to modify or copy the data pointed to by pointer p, use (*p) to access the data pointed to by the pointer;

    When you want to point the pointer p to another piece of data, that is, to modify the address stored in p, p is used to calculate.

  6. Anonymous users2024-02-01

    int* p;

    int* is the type of pointer;

    p is a pointer address;

    p is the value that p points to the address;

    Don't memorize things by rote, rote memorization is never yours.

  7. Anonymous users2024-01-31

    Use * to retrieve the memory in the address pointed to by the pointer, and not to refer to the address pointed to by the pointer.

  8. Anonymous users2024-01-30

    Because pointers pass parameters through addresses, they are slow to pass without a pointer.

    In the era when there was no C++ language, there was no object-oriented, template-oriented syntax support, and functions could not be defined in the struct, and the C language wanted to abstract the business function (algorithm, here referred to as the function), and did not want to rely on the specific data structure Data type, at this time, it was necessary to use a pointer to the function to achieve the separation of abstraction and concreteness, and the input parameter of the function could be void*, so that the caller could pass in any type of parameter. Later, with C++, class member functions and generics (template + functor) were used instead, which had a stronger static type checking mechanism and programming constraints, which helped to reduce the risk of abuse.

    A typical application of function pointers is to implement **, because the specific function definition is not known at this time, and the event is called and determined when it occurs; Analogous to "polymorphism" in object-oriented + "observer mode" in design patterns, the essence of ** is still abstraction.

  9. Anonymous users2024-01-29

    Represents the member selection (pointer) that selects the member variables of the struct.

    1. Structure simplicity: The operator -> is an operator pointing to the member of the structure, and the binding direction is from left to right.

    2. Usage: Object pointer - > member name.

    Here are some examples:

  10. Anonymous users2024-01-28

    In C, a pointer is a special variable that stores a memory address. This address can point to the location of a specific data object (such as a variable, array, struct, etc.) in memory.

    The ability to use pointers allows programs to dynamically access and modify data in memory at runtime, which is one of the characteristics of the C language and one of the reasons why it is widely used.

    In C, pointers use an asterisk (*) to declare and manipulate. For example, here's an example of a pointer variable that declares a pointer variable to an integer type:

    arduinocopy codeint *p;

    This statement declares a pointer variable called "p", which can point to an integer type of data. To access the data in memory pointed to by the vertical needle, you can use an address character (&) to assign the address of a variable to the pointer variable, or you can assign a known address directly to the pointer variable. For example:

    arduinocopy codeint x = 10;

    p = x;Assign the address of x to p

    or: arduinocopy codeint *p = int *)0x12345678; Assign the address 0x12345678 to P

    To access the data that the pointer points to, you can use a dereference (*) to take out the value in memory that the pointer points to. For example:

    arduinocopy codeint y = p;Take an integer value from the address pointed to by the pointer p and assign it to y

    Pointers can also be added and subtracted to move the pointer's position in memory. For example:

    csscopy codep++;Move the pointer p backward by an integer type of forest cover length p--; Moves the pointer p forward by the length of an integer type.

    The use of pointers requires some details, such as the type matching of pointers, the handling of pointer null pointers, etc., otherwise it may cause the program to crash or have difficult errors. Therefore, you need to be very careful when using the pointers.

  11. Anonymous users2024-01-27

    1.You can use pointers at any time, because they are more efficient than variables.

    3.When manipulating arrays, using pointers is not only much more convenient but also very time-efficient.

    4.When working with files, it's hard to move without a pointer.

    5.Pointers simplify the process of writing function calls and make the source easy to read.

    It's not a word.

  12. Anonymous users2024-01-26

    It is recommended that you read the program first and learn as you understand.

  13. Anonymous users2024-01-25

    It is recommended that you should not struggle with when to use the pointer. Instead, aim to understand and learn: what the essence of the pointer is.

  14. Anonymous users2024-01-24

    Because pointers pass parameters through addresses, they are slow to pass without a pointer.

    In the era when there was no C++ language, there was no object-oriented, template-oriented syntax support, and functions could not be defined in the struct, and the C language wanted to abstract the business function (algorithm, here referred to as the function), and did not want to rely on the specific data structure Data type, at this time, it was necessary to use a pointer to the function to achieve the separation of abstraction and concreteness, and the input parameter of the function could be void*, so that the caller could pass in any type of parameter. Later, with C++, class member functions and generics (template + functor) were used instead, which had a stronger static type checking mechanism and programming constraints, which helped to reduce the risk of abuse.

    A typical application of function pointers is to implement **, because the specific function definition is not known at this time, and the event is called and determined when it occurs; Analogous to "polymorphism" in object-oriented + "observer mode" in design patterns, the essence of ** is still abstraction.

  15. Anonymous users2024-01-23

    It can be used in many situations. This requires the formation of a mindset in the programming process.

    e.g. pass a struct to a function.

    If you don't use a pointer, the transfer speed is slow, and if you pass a pointer, you only need to pass an address.

    struct example

    void main()

    fun(struct example *p)

  16. Anonymous users2024-01-22

    The pointer passes the parameter through the address, which can pass the value in both directions.

    If you are a computer science student, read "High-level Language Programming" for a detailed description of the difference between the two, as well as program comparison (a function of two numbers exchanged). I'm lazy, you're on your own.

  17. Anonymous users2024-01-21

    A pointer can be thought of as a slip of paper with the address of the entry point of a variable or function or the specific location of the struct, and if memory is compared to a building, then the note is written on the number of floors and rooms. The use of the pointer means that you can find the corresponding room according to the address on the note, and take out the contents of the room and do what you need.

    There are many situations where pointers are used, the most common being when the called function returns multiple parameters; It will be used to make various linked lists; Access to struct members will be used; Manual dynamic allocation of memory usage will be used; Some specific struct variable types will be used (such as file), and pointers will be deliberately used to improve the efficiency of program execution (including many cases, so I will not repeat them); And so on and so forth.

    There are a lot of things to pay attention to, and it is difficult to finish, but the common ones are the following (I can think of):

    1.The concepts of pointer variables and ordinary variables are used in a way that is confused.

    2.The pointer variable is assigned in the wrong way (initialization, passing the address)3The type of the pointer variable does not match the type of the referent element.

    4.The pointer is not moving properly.

    5.The pointer has been changed unnecessarily during use, resulting in an error6There are many other situations where multiple pointers point to pointers, resulting in the formation of logical relationships that are difficult to sort out, and in different use environments, pointers will produce some specific problems to pay attention to; At the end of the day, C pointers are so flexible that they can do a lot of things, and the cost is that the causes of the problems are also very flexible, and it's almost impossible to list them all.

    Hope it helps.

  18. Anonymous users2024-01-20

    Let's be honest, the essence of C language is the pointer, no one can help you solve this problem, go read the book.

    Recommended "C and Pointers" explains in detail, the difficulty of self-study is a bit big, this is a freshman course, what about you? It's 、、、

  19. Anonymous users2024-01-19

    Personal understanding.

    A pointer is an address, but this address has a type, such as an int pointer, int refers to the content of the memory that the pointer points to is an int type of data.

    Or you can simply think of the type of pointer as the size of the memory that the pointer can manage, for example, an int pointer can manage 4 bytes, and a char type can manage 1 byte.

  20. Anonymous users2024-01-18

    It's the address of the data. A pointer can be used to write data to this address, or to read data. p is the address, and *p is the content of the address.

  21. Anonymous users2024-01-17

    The C pointer is the memory address. Since it is a memory address, of course, you can use it to access memory. So it's used when you want to read, write, allot, and release memory.

    You can even use a function pointer to access a function. The things to pay attention to cannot be said for a while, and this needs to be summarized by one's own practice.

  22. Anonymous users2024-01-16

    In fact, instead of asking here, it is better to take a look at the C language textbook, which is written in great detail.

    The following is Tan Haoqiang's version.

    In a computer, all data is stored in memory. Generally, a byte in memory is called a memory unit, and the number of memory cells occupied by different data types is different, such as the number of integers accounts for 2 units, the number of characters accounts for 1 unit, etc., which have been described in detail before. In order to properly access these memory cells, each memory cell must be numbered.

    A memory cell can be accurately located by its number. The number of a memory cell is also called an address.

    Since you can find the memory cell you need by its number or address, it is common to refer to this address as a pointer.

    The pointer of a memory cell and the contents of a memory cell are two different concepts.

    A layman's example can be used to illustrate the relationship between them. When we go to the bank to deposit and withdraw money, the bank staff will look for our deposit slip according to our account number, and then write the deposit and withdrawal amount on the deposit slip. Here, the account number is the pointer of the certificate of deposit, and the number of deposits is the content of the certificate of deposit. For a memory cell, the address of the cell is the pointer, and the data stored in it is the content of the cell. In C, it is allowed to store pointers in a variable, which is called a pointer variable.

    Thus, the value of a pointer variable is the address of a memory cell, or a pointer called a memory cell.

    Strictly speaking, a pointer is an address, a constant. A pointer variable can be given a different pointer value, which is a variable. However, pointer variables are often referred to simply as pointers.

    To avoid confusion, we agree that "pointer" refers to an address and is a constant, and "pointer variable" refers to a variable whose value is an address. The purpose of defining a pointer is to access a memory cell through a pointer.

    Since the value of a pointer variable is an address, it can be not only the address of the variable, but also the address of other data structures. What's the point of keeping the first address of an array or a function in a pointer variable?

    This is because arrays or functions are stored continuously. The first address of an array or function is obtained by accessing the pointer variable, and the array or function is found. In this way, wherever an array or function appears, it can be represented by a pointer variable, as long as the first address of the array or function is given in the pointer variable.

    In doing so, the concept of the program will be very clear, and the program itself will be concise and efficient. In C, a data type or data structure often occupies a contiguous set of memory units.

    The concept of "address" does not describe a data type or data structure very well, while "pointer", although it is actually an address, is the first address of a data structure, it is "pointing" to a data structure, so the concept is clearer and the representation is more explicit.

    This is also an important reason for the introduction of the concept of "pointer".

Related questions
8 answers2024-03-02

It is the return value of the subfunction, and the main function also has a return value, but it is generally not used and ignored. >>>More

6 answers2024-03-02

Define the struct:

typedef struct _legaladdress_{ >>>More

13 answers2024-03-02

Go to bed at 10 o'clock at night at the latest but more than 11 o'clock, the best time for beauty sleep is from 10 o'clock in the evening to 2 o'clock in the middle of the night, this time period of the body's various functions begin to carry out corresponding detoxification activities, night is our most vigorous metabolism time, we must use this time to achieve the effect of sleep beauty.

26 answers2024-03-02

These are a matter of proficiency, first of all, you have to understand the skills of your heroes, the skills of the opposite hero, whether you will be stunned in the past, whether you can kill, whether you can control, whether you can come back alive. That is to say, before you rush, you have to know a little bit about the consequences of rushing over, and you have nothing to say when you kill halfway. Knowing how much damage you can do and how much help you can give your teammates is a matter of how good you are at the game. >>>More

7 answers2024-03-02

Lunar calendar male September 23, 1984, female December 16, 1985. >>>More