c primer plus答案里提到的一句,原文如下:
下面是第二种方案,它防止函数修改字符串,但是允许使用返回值来改变字符串。表达式(char *)string被称为“使用类型指派取消const”。
#include<stdio.h> /*提供NULL的定义 */
char * strblk(const char* string)
{
while(*string!=' '&&*string!='\0')
string++; /*在第一个空格或空字符处停止*/
if(*string=='\0')
return NULL; /*NULL是空指针*/
else
return (char *)string;
}
它有什么意义?
下面是第二种方案,它防止函数修改字符串,但是允许使用返回值来改变字符串。表达式(char *)string被称为“使用类型指派取消const”。
#include<stdio.h> /*提供NULL的定义 */
char * strblk(const char* string)
{
while(*string!=' '&&*string!='\0')
string++; /*在第一个空格或空字符处停止*/
if(*string=='\0')
return NULL; /*NULL是空指针*/
else
return (char *)string;
}
它有什么意义?