Home > Back-end >  What is the difference between the two procedures, please
What is the difference between the two procedures, please

Time:10-08

Two application results are different?

CodePudding user response:

Is very simple, you changed should not change the memory of you, the two are,

CodePudding user response:

The difference between big
Char * a="KDKDLKDDK"//this string is const char * won't change
Char []//this is an array, a content literally change

CodePudding user response:

First you dialed the wrong number, to determine the size, copy can't target must be larger than the source, otherwise or error,

CodePudding user response:

Fun
reference 2 floor response:
the difference between big
Char * a="KDKDLKDDK"//this string is const char * won't change
Char []//this is an array, a content literally change
the first char * from=a why is ok

CodePudding user response:

The difference between the first and the second only in [] and ". "char * from=this sentence is not a root cause

CodePudding user response:

The
reference 5 floor ggglivw response:
the difference between the first and the second only in [] and ". "char * from=this sentence is not a root
the first char a []=" XXXX ". Char * from=a;
The second char a *="XXXX"; The first can get correct results can not be the second

CodePudding user response:

First, that is to initialize, put the string is a copy of an array, the array is not in read-only memory area, reading and writing are no problem
The second, that same is initialized, but is a read-only buffer address gave the two char * variables, the write operation is in the read only memory, unable to write a successful



CodePudding user response:

You try, a [1]='X'; B [1]='y'
You can see, the first writing, can the changes to take effect; The second kind of writing, the estimate is a tip to collapse

CodePudding user response:

See, thank you

CodePudding user response:

Fun
reference 7 floor response:
first, that is to initialize, put the string is a copy of an array, the array is not in read-only memory area, reading and writing are no problem
The second, that same is initialized, but is a read-only buffer address gave the two char * variables, the write operation is in the read only memory, can't write success
thank you understand
  • Related