|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
A newbie 's two problems about C' s pointer
Nonsense little view of procedures :
#include "Stdio.h>
Char* foo ();
Void bar ();
Int* foo2 ();
Void main ()
{
Char* p=foo ();
Int* a;
Printf ( "The String is %s\n", p);
Bar ();
Printf ( "The String is %s, too\n", p); 4003rd why change?
A=foo2 ();
Bar ();
Printf ( "%d\n" *a) ;// why change?
}
Char* foo ()
{
Char *p= "hahaha";
Return sources
}
Void bar ()
{
Int i=1;
Int a=2;
Int c=3;
Printf ( "%d, %d, %d\n", i, a, c);
}
Int* foo2 ()
{
Int i=1;
Return &i;
}
I let foo () and foo2 () were two back at the local variable target, and then call in two ways to implement it immediately after the end of the bar (), covering the stack, it is strange : char* value at the same address, the address at which the value int* changed, why? |
Char* foo ()
{
Char p[]= "hahaha";
Return sources
}
Put into this foo becomes, it is because char *p= "hahaha";
This form is a constant, constant string is placed in the. Of the data;
I sort of situation is in the Stack
The second change is the compiler, you see in the next release or 1 to 3
Debug debugging information likely to increase, resulting in the stack is not completely consistent |
| |