It is still related to pointers and memory. Recently I read Mr Lin'sArticle, Write someCodeIf you are interested, let's take a look. What are the answers?
ProgramIt is compiled with vc6 + SP6, with compilation problems and runtime problems...
Q1-Q8, all output what content ???
(Temporarily put the homepage for a few days and withdraw it at that time)
# Include "string. H"
# Include "stdlib. H"
Char * getname (void ){
Char name [20] = "juqiang ";
Return name;
}
Int getsize (char Buf []) {
Return sizeof (BUF );
}
Int main (INT argc, char * argv [])
{
Char Buf [] = "hello ";
Printf ("size of BUF is: % d \ r \ n", sizeof (BUF); // Q1
Printf ("size of BUF calling is: % d \ r \ n", getsize (BUF); // Q2
Printf ("Hello % s \ r \ n", getname (); // Q3
Char * P = (char *) malloc (100 );
Int paddr = (INT) P;
Free (P );
Int paddr2 = (INT) P;
Printf ("paddr equals paddr2 is: % d \ r \ n", paddr = paddr2); // Q4
If (null! = P ){
Strcpy (P, "Hello! ");
}
Printf ("the contents of P is: % s", P); // Q5
Char name [] = "juqiang ";
Name [0] = 'J ';
Name [1] = 'U ';
Printf ("name is: % s \ r \ n", name); // Q6
Char bufname [] = "juqiang ";
Char * name2 = bufname;
* (Name2 + 0) = 'J ';
* (Name2 + 1) = 'U ';
Printf ("name is: % s, % s \ r \ n", bufname, name2); // Q7
Char * name3 = "juqiang ";
* (Name3 + 0) = 'J ';
* (Name3 + 1) = 'U ';
Printf ("name is: % s \ r \ n", name3); // Q8
Return 0;
}