I have a question about the C language double pointer.

Asked 2 years ago, Updated 2 years ago, 41 views

They created a two-dimensional array of chars, and they also created a pointer to it. I want the pointer to point to a[0][1], so I did (*pa)++ (I know pa is the pointer to a, *pa is the pointer to the first row of a, and **pa is the pointer to the first value of the first row). I don't know why. Please help me ㅠ<

#include <stdio.h>
int main()
{
        char a[100][100];
        char (*pa)[100];

        pa=a;

        a[0][0]='a';
        a[0][1]='e';
        a[1][0]='g';

        (*pa)++;
        printf("%c\n",*(*pa+1));
}

pointer c

2022-09-20 20:52

1 Answers

The potential/post increment operator is only available for changeable lvalue.

++b is equivalent to b = b+1. b++ is equivalent to temp = b; b = b + 1; temp The value is eventually substituted for b whether it is a potential or a posterior. In order to substitute a value for b, b must be a variable.

If you look at (*pa)++, *pa is an array of characters with 100 elements. The array is also converted to the address of the first element, so (*pa) becomes the address value of a[0].

The address value is not a variable, so it is not a substitution operation. Potential/postal increment operator is not available because it is not a substitution operation.

Simply put, (*pa)++ is not allowed, such as why (1)++ is not allowed.


2022-09-20 20:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.