
malloc()函数代表内存分配,动态分配一块内存。
它保留指定大小的内存空间,并返回指向内存位置的空指针。
malloc() 函数携带垃圾值。返回的指针是void类型。
malloc()函数的语法如下 -
立即学习“C语言免费学习笔记(深入)”;
基于jsp+javabean+mysql三层结构的动态购物网站。网站用户接口(即界面)由jsp完成,数据和逻辑处理由beans完成,数据储存由mysql完成。因为beans独立负责处理整个网站的绝大部分数据,所以整个网站的负载量和速度都将大大提高。而且jsp的特性是一次运行,永远储留内存(包括bean在内),所以基于这种语言和结构开发的购物系统的优势是其它语言没法比尔的。更重要的是,jsp+bea
ptr = (castType*) malloc(size);
示例
以下示例展示了 malloc() 函数的用法。
现场演示
#include#include #include int main(){ char *MemoryAlloc; /* memory allocated dynamically */ MemoryAlloc = malloc( 15 * sizeof(char) ); if(MemoryAlloc== NULL ){ printf("Couldn't able to allocate requested memory "); }else{ strcpy( MemoryAlloc,"TutorialsPoint"); } printf("Dynamically allocated memory content : %s
", MemoryAlloc); free(MemoryAlloc); }
输出
当执行上述程序时,会产生以下结果 -
Dynamically allocated memory content: TutorialsPoint










