linux下 C程序 参数和内存

#include <stdio.h>
int main(argc, argv)
int argc;char *argv[];
{
    printf("argc=%d \n",argc);
    int i;
    for(i=0;i<argc;i++)
    {
        printf("argv[%d]=%s \n",i,argv[i]);
    }

    char arr1[]="i think is boring";
    printf("strlen arr=%d\n",strlen(arr1));/*17*/
    printf("sizeof arr=%d\n",sizeof(arr1));/*18*/

    char *pointer=NULL;
    pointer=(char *)malloc(1000);
    printf("malloc strlen pointer=%d\n",strlen(pointer));/*0*/
    printf("malloc sizeof pointer=%d\n",sizeof(pointer));/*4*/
    
    memset(pointer,0,1000);
    printf("memset strlen pointer=%d\n",strlen(pointer));/*0*/
    printf("memset sizeof pointer=%d\n",sizeof(pointer));/*4*/
    
    memcpy(pointer,arr1,strlen(arr1));
    printf("memcpy arr1 to pointer=%s\n",pointer);/*i think is boring*/
    printf("memcpy strlen pointer=%d\n",strlen(pointer));/*17*/
    printf("memcpy sizeof pointer=%d\n",sizeof(pointer));/*4*/
    
    if(pointer!=NULL)
    {
        free(pointer);
        pointer=NULL;
    }
    return 0;
}

收藏于 2011-05-05

posted on 2015-06-01 15:09  阮減显  阅读(119)  评论(0编辑  收藏  举报

导航