C arrays cannot be used as pointers, but pointers can be used as arrays

Updated on technology 2024-02-17
16 answers
  1. Anonymous users2024-02-06

    Array of pointers. First of all, it is an array, the elements of the array are all pointers, and the number of bytes occupied by the array is determined by the array itself. It is short for "array of stored pointers".

    Array pointers. First it's a pointer, which points to an array. In a 32-bit system, it will always be 4 bytes, and I don't know how many bytes it points to in an array. It is short for "pointer to array".

    For example, define int *w

    The bottom can then be used as w[i].

    Is that right? If so, under what circumstances can I use it like this?

    A: No, because W is still a field pointer at this time.

    That's the only way. int *w,a[44];

    w=a;After the operation, operation w is the same as operation a. Also, manipulating pointers is more convenient than manipulating array names directly, because pointers are variables and can be ++, while array names are constants.

    No++, the question in the red box you are asking is not a question of pointers and array names, but a question of "formal parameters" and "actual parameters". The variable preceded by the type specifier in the () defined by the write function is called a formal parameter. Compared with the arguments, the biggest feature of the form is that you don't have to worry about using the reference without assignment or initialization, they are reserved for the call before the argument is automatically assigned.

    On the other hand, if you use an argument as an rvalue when you don't have an assignment, you will be warned that you are referencing an uninitialized variable, and because the initial value is random, the result is generally wrong.

  2. Anonymous users2024-02-05

    inta[10]

    intp=a

    Defines a one-dimensional pointer p and points to the first address of array a.

    p=a+2 points to the third element of the array a.

    Or write it as: p=

    a[2] takes the address of a[2] by means of the & operator and assigns it to pp=&a This is the wrong statement! Because, the type of &a is int*, and p is int

    type, therefore, the type does not match, and the assignment operation cannot be performed.

  3. Anonymous users2024-02-04

    Array pointers (also known as row pointers).

    define int (*p)[n];

    The priority is high, first of all, p is a pointer pointing to an integer-type one-dimensional array, and the length of this one-dimensional array is n, which can also be said to be the step size of p. In other words, when p+1 is executed, p must span the length of n integer data.

    If you want to assign a two-dimensional array to a pointer, you should assign a value like this:

    int a[3][4];

    int (*p)[4];This statement defines an array pointer that points to a one-dimensional array of 4 elements.

    p=a;Assign the first address of the two-dimensional array to p, i.e. a[0] or &a[0][0].

    p++;After the statement is executed, it is p=p+1; p crosses line a[0] and points to line a[1].

    Therefore, array pointers are also called pointers to one-dimensional arrays, also known as row pointers.

    Array of pointers. define int (*p)[n];

    The priority is high, first combined with p to form an array, and then int* indicates that this is an integer pointer array, which has n pointer type array elements. When p+1 is executed here, p points to the next array element, so the assignment is wrong: p=a; Because p is an unknowable representation, there are only p[0], p[1], p[2].

    p[n-1], and they are pointer variables that can be used to store variable addresses. But it can be like this *p=a; Here *p denotes the value of the first element of the pointer array, and the value of the first address of a.

    If you want to assign a two-dimensional array to a pointer array:

    int *p[3];

    int a[3][4];

    for(i=0;i<3;i++)

    p[i]=a[i]

    Here int *p[3] indicates that there are three pointer variables stored in a one-dimensional array, which are p[0], p[1], and p[2].

    So assign values separately.

  4. Anonymous users2024-02-03

    Array pointers.

    bai (also known as line pointer) defines int (*p)[n]; High priority.

    du, first of all, p is a pointer pointing to an integer DAO one-dimensional version of the array, and the length weight of this one-dimensional array is n, which can also be said to be the step size of p. In other words, when p+1 is executed, p must span the length of n integer data. If you want to assign a two-dimensional array to a pointer, you should assign a value like this:

    int a[3][4]; int ..

  5. Anonymous users2024-02-02

    int **p[10]

    In fact, the array is the pointer, think about the difference, the array variable name is the first memory address of the memory block, and a memory address is the content of a pointer.

  6. Anonymous users2024-02-01

    int *arry[10];Pointer array copy

    baiint (*arryp)[10];Array pointer, because the number du pointer points to the array, and the array is also.

    It can be seen as a pointer, and the array pointer can be understood as a second-order pointer int a[10];

    arryp = &a;arry[0] = *arryp; arry[0] is a first-level pointer, to assign an array pointer to a pointer array, you need to take the content, which is actually arry[0] = a;

  7. Anonymous users2024-01-31

    Pointers have types, arrays have sizes, and an array of pointers is roughly as follows:

    type * name[size];Type can be void, char, int, long, etc.

  8. Anonymous users2024-01-30

    int *a[10], this copy definition will do, and each value in the array is a pointer.

    Technology Department of China Internet of Things School-Enterprise Alliance.

  9. Anonymous users2024-01-29

    #include int zuhe(int n,int k)else

    temp1 /=temp2;

    return temp1; }

    void main()

    num = zuhe(n,k);

    printf("%d",num);}

    Or do it this way.

    int fun(int n,int k)

    void main()

  10. Anonymous users2024-01-28

    Let's say the class name is object

    1. The pointer to the array of objects:

    object objects[100];

    object (*pobjects)[100];That's it pobjects = &objects;It must be the same length as the objects in order to be assigned as such.

    2. Array of object pointers:

    object* objects[100];

    3. C++1) C++ is the inheritance of C language, which can not only carry out the process programming of C language, but also carry out object-based programming characterized by abstract data types, and can also carry out object-oriented programming characterized by inheritance and polymorphism. C++ excels at object-oriented programming as well as process-based programming, so C++ is based on the size of the problem it can adapt to.

    2) C++ not only has the practical characteristics of efficient computer operation, but also is committed to improving the programming quality of large-scale programs and the ability to describe problems in programming languages.

  11. Anonymous users2024-01-27

    Are you sure it's the pointer to the array of objects, not the array of object pointers?

    Let's say the class name is object

    The pointer to the object's array:

    object objects[100];

    object (*pobjects)[100];That's it pobjects = &objects;It must be the same length as the objects in order to be assigned as such.

    Array of object pointers:

    object* objects[100];

  12. Anonymous users2024-01-26

    Array definition: type identifier[num];

    type: can be any type, int, long, float, int*, long*, class, class*, etc

    identifier: The identifier.

    num: the length of the array.

    The contents of the array are entities of type type.

    type* p_id = identifier;

    The p id is a pointer to an array of type types.

    When a class is used as a type in C++, it is no different from the int and float basic types, except that there are more members and functions, so there is no need for special treatment.

  13. Anonymous users2024-01-25

    class a

    a (*p)[5];

    then p points to an array of objects containing five objects.

  14. Anonymous users2024-01-24

    First of all, you have to understand that array names and pointers are essentially the same thing, they are both addresses, the first address of the array. Once you know this, you can learn and put it into practice. This is the essence of the C language.

    Let's say you define int

    p,a[10];And let p=a;This operation is called the pointer p pointing to the array a, and its essence is to pay a value to the variable p, which is the address of array a, the address of a[0], and the content stored in a itself.

    Then to quote a[i], you can write it in many ways, such as *(a+i), *p+i), p[i], all of which are equivalent.

    The meaning of p++ is not p=p+1, at least sometimes it is not, the operation of p++ is actually to point p to the next element, that is, p points to a[0], so now p points to a[1]. Since a is an int type and stands 4 bytes, then the operation p++ actually adds 4 to the content of p. Don't ask why, that's what C prescribes.

    If p points to a char type, then p++ increases the value of p by 1.

  15. Anonymous users2024-01-23

    If you want to express a[i], the most commonly used a[i] can also be *(a+i) or *(p+i)c: expression 1 [expression 2] and .

    (Expression 1) + (Expression 2)) is completely equivalent, it can also be said that a[b] and b[a] are also completely equivalent, that is to say, a[i] and i[a] are also completely equivalent, you can try.

  16. Anonymous users2024-01-22

    *p*a

    p=a means that the first address of the array is assigned to the pointer p

    This will point to the array.

    p++ indicates that the pointer p address is added by 1

    This points to the latter address.

Related questions
6 answers2024-02-17

First of all, it depends on which disk your system is installed in (usually in the C drive), and it doesn't matter if the system is not in the C drive. Except for system files, all other files can be deleted.

12 answers2024-02-17

The "Motor Vehicle Driver's License Business Work Specification" stipulates that the introduction of a grading system for motor vehicle driver's licenses, which divides driver's licenses into 15 categories: A1, A2, A3, B1, B2, C1, C2, C3, C4, D, E, F, M, N, and P. >>>More

6 answers2024-02-17

Yes, like HTML, XML are all Internet languages.

11 answers2024-02-17

No, smoke is poisonous, you know it's poisonous, you still smoke it, and a lot of people inhale your second-hand smoke, which is really a big sin, it's really harmful to others and yourself, which is contrary to the Dharma. >>>More

31 answers2024-02-17

Hehe, it's good to be very demanding, and you can't understand the skills and abilities of the characters at once. >>>More