memset函数的实现&printf函数几种输出格式的输出结果

#include<stdio.h>
#include<stdlib.h>

void *memmset(void *dest, int ch, int count){
void *dest_init = dest;
char* temp = (char*)dest;
int i=0;
for(; i<count;i++){
*temp=(char)ch;
temp++;
}
return dest_init;
}

int main(void){
int count =sizeof(int)*2;
char ch='A';
char *dest = malloc(sizeof(int)*2);

if(dest!=NULL){
printf("init dest value:%d\n",dest);
printf("original dest value:%d\n",*dest);
printf("init dest value:%s\n",dest);
printf("init dest value:%s\n",*dest);

memmset(dest,ch,count);

printf("init dest value:%d\n",dest);
printf("original dest value:%d\n",*dest);
printf("init dest value:%s\n",dest);
printf("init dest value:%s\n",*dest);
}else{
printf("dest is NULL\n");
return -1;
}
free(dest);

return 0;
}

memset 之后, printf("init dest value:%c\n",*dest); 可打印出dest首地址的存储内容。

 

posted @ 2018-09-07 18:23  谦学的故事  阅读(308)  评论(0编辑  收藏  举报