首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

关于栈,堆以及数据段的有关问题

2012-09-01 
关于栈,堆以及数据段的问题下面的程序能够编译而且也能够正常运行,但其中包含了多处错误。请一一指明错误所

关于栈,堆以及数据段的问题

下面的程序能够编译而且也能够正常运行,但其中包含了多处错误。

请一一指明错误所在并说明原因。 ?求助啊。。

?

#include <stdio.h>

#include <stdlib.h>

#include <malloc.h>

#include <string.h>

int global = 1 ;

char* string;

?

void hello(){

strcpy(string , "Hello World!");

printf("%s\n" , string);

}

?

int *foo1(){

return &global;

}

?

int *foo2(){

int i = 2 ;

int *p = &i ;

return p ;

}

?

int *foo3(){

static int i = 3 ;

return &i ;

}

?

int *foo4(){

int *p = (int *)malloc(sizeof (int));

*p = 4 ;

return p ;

}

void bar(){

int *p;

p = foo1();

//printf( "%d\n" , p);

printf( "%d\n" , *p);

p = foo2();

//printf( "%d\n" , p);

printf("%d\n" , *p);

p = foo3();

//printf( "%d\n" , p);

printf("%d\n" , *p);

p = foo4();

//printf( "%d\n" , p);

printf( "%d\n" , *p);

}

?

int main(int argc , char* argv[]){

// h e l l o ( ) ;

bar();

system("pause" ) ;

return 0 ;

}

热点排行