void Func ( char str[100] )
{
sizeof( str ) = ? str此时是数组名也是四个字节(其实是4)
}
Func ( char str[100] )函数中数组名作为函数形参时,在函数体内,数组名失去了本身的内涵,仅仅只是一个指针;在失去其内涵的同时,它还失去了其常量特性,可以作自增、自减等操作,可以被修改。
(这句话什么意思啊???)
数组名不是常量吗,其值不能进行改变,但是为什么这里说可以进行自增自减运算呢?如果一个实参a[],把a传递给Func函数之后,在函数里面,a能进行赋值,自增自减运算吗??
void GetMemory1( char *p, int num)
{
p= ( char* )malloc(num);
}
void Test1( void )
{
char* str=NULL;
GetMemory1(str, 100 );
strcpy(str, " hello world " );
printf(str);
}
这段代码运行后为什么会导致系统崩溃啊。" hello world "为什么不能拷贝到str里面??
char * GetMemory4( void )
{
char *p=" hello world " ;
return p;
}
void Test4()
{
char *str=NULL;
str=GetMemory4();
printf(str);
}
这段代码中,*P是局部变量,GetMemory4调用结束后*p会被销毁,但是P的地址为什么能成功返回
char *GetMemory5( void )
{
char *p=( char* )malloc( 100 );
strcpy(p, " hello world " );
return p;
}
void Test5()
{
char *str=NULL;
str=GetMemory5();
printf(str);
free(str);
}
这段代码中GetMemory5函数中的P指针没有被初始化,strcpy(p, " hello world " );
会不会篡改了内存内容???
小弟基础知识太过薄弱,请各位指教,会有这方面的详细讲解资料,也请不吝分享,谢谢