Rewriting code with pointer to array results in compilation error

Asked 2 years ago, Updated 2 years ago, 34 views

"Regarding the function pal that I asked in ""I don't know what function to do", I used a pointer for the function, but if I were to write it without a pointer, I thought it would look like the following, so I got an error."What's wrong with you?

intpal(chars[])
{
    inti;
    chat[i] = s;
    while(t[i]!='\0'){
        t++;
    }
    t--; 
    while(s<=t){
        if(s[i]!=t){
            return 0;
        }
        s++;
        t--;
    }
    return1;
}

c

2022-09-29 21:57

2 Answers

There are many mistakes.
A value of 1i is neither initialized nor incremented.
It's called two arrays, but it's not an array index, it's increasing the pointer.
3 The first t is misconfigured.
4 Compare the pointer to the value indicated by the pointer (the i-th value of the array). (Assume t is the pointer)
and so on.
I think it's meaningless to write the answer, so I pointed out something that I think is wrong.


2022-09-29 21:57

It is recommended that you focus on "what is the same thing and what is different about pointer variables and arrays.
 Here are some tips:

  • The pointer variable is literally a variable, so you can change the contents of the pointer variable.
  • The array name represents an address and cannot be rewritten to another address.

    As a guess, the person who asked me may remember the array in the execution statement in the form of array [additional letter].
     In the execution text, the array name [accompanies] indicates the ではarray element 」 of the location indicated by the subscript, not the array.
     I think you should understand the difference between array and array elements.
     Array elements are rather the same as variables and can be modified.You cannot change the address indicated by the array name.

The array name represents an address and cannot be rewritten to another address.

As a guess, the person who asked me may remember the array in the execution statement in the form of array [additional letter].
 In the execution text, the array name [accompanies] indicates the ではarray element 」 of the location indicated by the subscript, not the array.
 I think you should understand the difference between array and array elements.
 Array elements are rather the same as variables and can be modified.You cannot change the address indicated by the array name.


2022-09-29 21:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.