niusouti.com

下列程序在32位linux或unix中的结果是什么?func(char *str){printf("%d",sizeof(str));printf("%d",strlen(str));}main(){char a[]="123456789";printf("%d",sizeof(a));func(a);}

题目

下列程序在32位linux或unix中的结果是什么?

func(char *str)

{

printf("%d",sizeof(str));

printf("%d",strlen(str));

}

main()

{

char a[]="123456789";

printf("%d",sizeof(a));

func(a);

}


相似考题
更多“下列程序在32位linux或unix中的结果是什么?func(char *str){printf("%d",sizeof(str));printf( ”相关问题
  • 第1题:

    下列程序在32位linux或unix中的结果是什么?

    func(char *str)

    {

    printf(" %d",sizeof(str));

    printf(" %d",strlen(str));

    }

    main()

    {

    char a[]="123456789";

    printf(" %d",sizeof(a));

    printf(" %d",strlen(a));

    func(a);

    }


    正确答案:

     

    10 9 4 9

  • 第2题:

    下列程序的运行结果为includevoid abc(char * str){ int a,b;for(a=b=0;str[a]!='\0';

    下列程序的运行结果为 #include<stdio.h> void abc(char * str) { int a,b; for(a=b=0;str[a]!='\0';a++) if(str[a]!='c') str[b++]=str[a]; str[b]='\0';} void main() { char str[]="abcdef"; abc(str); printf("str[]=%s",str);}

    A.str[]=abdef

    B.str[]=abcdef

    C.str[]=a

    D.str[]=ab


    正确答案:A
    解析:本题考查了用字符指针引用字符数组中的字符及对字符的操作。函数abc()的for语句执行过程是:从字符指针str所指向的字符数组的第一个元素开始,逐一判断字符是否为“c”,若不是就执行一次数组元素的赋值过程,若字符为“c”就不执行。

  • 第3题:

    阅读下面程序,则执行后的结果为_____ #include <stdio.h>    int main()   { char *str="abcdefghijklmnopq";   while(*str++!=′e′);   printf("%cn",*str);  }


    程序出现异常

  • 第4题:

    下面的程序各自独立,请问执行下面的四个TestMemory 函数各有什么样的结果?

    ①void GetMemory(char * p)

    {

    p = (char * )malloc(100);

    }

    void TestMemory (void)

    {

    char *str = NULL;

    GetMemory (str);

    strcpy(str, "hello world");

    prinff(str);

    }

    ② char * GetMemory (void)

    {

    char p[ ] = "hello world";

    return p;

    }

    void TestMemory (void)

    {

    char * str = NULL;

    str = GetMemory( );

    printf(str);

    }

    ③void GetMemory(char * * p, int num)

    {

    * p = (char * )malloc(num);

    }

    void TestMemory (void)

    {

    char * str = NULL;

    GetMemory(&str, 100);

    strcpy( str, "hello" );

    printf(sir);

    }

    ④void TestMemory (void)

    {

    char *str = (char * )malloe(100);

    strepy (str, "hello" );

    free ( str );

    if(str ! = NULL)

    {

    strepy( str, "world" );

    printf(str);

    }

    }


    正确答案:程序1程序崩溃。因为GetMemory并不能传递动态内存TestMemory函数中的str一直都是 NULL。strcpy(str “hello world”);将使程序崩溃。 程序2可能是乱码。因为GetMemory返回的是指向“栈内存”的指针该指针的地址不是 NULL但其原来的内容已经被清除新内容不可知。 程序3能够输出hello但是会发生内存泄漏。 程序4篡改动态内存区的内容后果难以预料非常危险。因为free(str);之后str成为野指针if(str!=NULL)语句不起作用。
    程序1程序崩溃。因为GetMemory并不能传递动态内存,TestMemory函数中的str一直都是 NULL。strcpy(str, “hello world”);将使程序崩溃。 程序2可能是乱码。因为GetMemory返回的是指向“栈内存”的指针,该指针的地址不是 NULL,但其原来的内容已经被清除,新内容不可知。 程序3能够输出hello,但是会发生内存泄漏。 程序4篡改动态内存区的内容,后果难以预料,非常危险。因为free(str);之后,str成为野指针,if(str!=NULL)语句不起作用。

  • 第5题:

    下列程序的运行结果为includevold abc(char*str){int a,b; for(a=b=0;str[a]!='\0';a+

    下列程序的运行结果为 #include<stdio.h> vold abc(char*str) { int a,b; for(a=b=0;str[a]! ='\0';a++) if(str[a]!='c') str[b++]=str[a]; str[b]='\0';} void main() { char str[]="abcdef"; abc(str); printf("str[]=%s",str);}

    A.str[]=abdef

    B.str[]=abcdef

    C.str[]=a

    D.str[]=ab


    正确答案:A
    解析:本题考查了用字符指针引用字符数组中的字符及对字符的操作。函数abc()的for语句执行过程是:丛字符指针str所指向的字符数组的第一个元素开始,逐一判断字符是否为'c',若不是就执行一次数组元素的赋值过程,若字符为'c'就不执行,所以答案为A)。