Home > Back-end >  For help
For help

Time:01-05

Strives for the bosses tell me something about this program, thank you

CodePudding user response:

Fun function string transpose

CodePudding user response:

S1=w first address pointer to a string (that is, s1 address the characters' 1 ')
S2=w + n - 1 pointer to the string of the last character address (that is, s2 point to the characters' 7 'address)
While (s1 & lt; Less than s2 s2) when s1 to address to address has been circulating
T=* s1. * s1=* s2; * s2=t; Is the exchange of s1 and s2 address characters, that is' 1 'into a' 7 ', '7' into a '1'
S1 + + is s1 to address increasing, namely s1 to '2' in the address of the
S2 - is diminishing s2 to address, namely s2 to '6' in the address
In this way, the next round of the while loop will exchange '2' and '6', and then the next round of exchange '3' and '5', then the next round, s1 to '4', s2 point to '4', does not meet the while, circulation end
So the final string into "7654321"

CodePudding user response:

Beginner C,
To understand the code, the first thing to understand, the difference between the pointer variable and common variables: the former is tells the compiler, store of value is an address; The latter is numerical,
So for the pointer variable p * p++ and (* p) + + there is a difference between,
Function, make two Pointers, a pointer to a head, a pointer to the end, according to the address, then interaction numerical size,
  • Related