niusouti.com

以下为 Windows NT 下的 32位 C++程序,请计算 sizeof的值char str[] = “Hello” ; char *p = str ;int n = 10;请计算 sizeof (str )= sizeof ( p ) = sizeof ( n ) = void Func (char str[100]){请计算 sizeof( str ) = }void *p = malloc( 100 );请计算 sizeof ( p ) =

题目

以下为 Windows NT 下的 32位 C++程序,请计算 sizeof的值

char str[] = “Hello” ; char *p = str ;int n = 10;请计算 sizeof (str )

= sizeof ( p ) = sizeof ( n ) = void Func (

char str[100]){请计算 sizeof( str ) = }

void *p = malloc( 100 );请计算 sizeof ( p ) =


相似考题
更多“以下为 Windows NT 下的 32位 C++程序,请计算 sizeof的值char str[] = “Hello” ; char *p = st ”相关问题
  • 第1题:

    有关内存的思考题

    1. void getmemory(char *p)

    { p=(char*)mallol(100);

    }

    void test(void)

    {

    char * str =null;

    getmemory(str);

    strcpy(str,”hello,world”);

    printf(str);

    }

    请问运行 Test 函数会有什么样的结果


    正确答案:
     

  • 第2题:

    下面的程序各自独立,请问执行下面的四个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)语句不起作用。

  • 第3题:

    35、以下程序的运行结果是___________。 void print(char *s){ printf("%s", s); } int main(){ char *p, *q; char str[]="Hello, World\n"; q=p=str; p++; printf(q); printf(p); return 0; }

    A.H e

    B.Hello, World ello, World

    C.Hello, World Hello, World

    D.ello, World llo, World


    x=3

  • 第4题:

    Void GetMemory2(char **p, int num){*p = (char *)malloc(num);}void

    Test(void){char *str = NULL;GetMemory(&str, 100);strcpy(str, "hello"); printf(str); }请问

    运行Test 函数会有什么样的结果?


    正确答案:
     

  • 第5题:

    以下程序的输出结果是【 】。includeincludechar*fun(char*t){ char *p=t;retur

    以下程序的输出结果是【 】。

    include <stdio.h>

    include <string.h>

    char *fun(char *t)

    { char *p=t;

    return (p+strlen(t)/2);

    }

    main()

    { char *str="abcdefgh";

    str=ftm(str);

    puts(str);

    }


    正确答案:
    efgh 解析:本题考查的知识点是:字符指针。题目中的fun()函数,通过strlen()库函数得到形参t所指字符串的长度。然后返回t所指字符串首地址值加上该长度值的一半。所以fun()函数的作用就是返回所给字符串的中间位置。故最后通过puts()输出的字符串为"efgh"。