Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

dz̸CÄÚ´æ·ÖÅä2

 ÄÚ´æ·ÖÅ䷽ʽÓÐÈýÖÖ£º
£¨1£© ´Ó¾²Ì¬´æ´¢ÇøÓò·ÖÅä¡£ÄÚ´æÔÚ³ÌÐò±àÒëµÄʱºò¾ÍÒѾ­·ÖÅäºÃ£¬Õâ¿éÄÚ´æÔÚ³ÌÐòµÄ
Õû¸öÔËÐÐÆÚ¼ä¶¼´æÔÚ¡£ÀýÈçÈ«¾Ö±äÁ¿£¬static ±äÁ¿¡£
£¨2£© ÔÚÕ»ÉÏ´´½¨¡£ÔÚÖ´Ðк¯Êýʱ£¬º¯ÊýÄÚ¾Ö²¿±äÁ¿µÄ´æ´¢µ¥Ôª¶¼¿ÉÒÔÔÚÕ»ÉÏ´´½¨£¬º¯
ÊýÖ´ÐнáÊøÊ±ÕâЩ´æ´¢µ¥Ôª×Ô¶¯±»ÊÍ·Å¡£Õ»ÄÚ´æ·ÖÅäÔËËãÄÚÖÃÓÚ´¦ÀíÆ÷µÄÖ¸Á
ÖУ¬Ð§Âʺܸߣ¬µ«ÊÇ·ÖÅäµÄÄÚ´æÈÝÁ¿ÓÐÏÞ¡£
£¨3£© ´Ó¶ÑÉÏ·ÖÅ䣬Òà³Æ¶¯Ì¬ÄÚ´æ·ÖÅä¡£³ÌÐòÔÚÔËÐеÄʱºòÓÃmalloc »ònew ÉêÇëÈÎÒâ¶à
ÉÙµÄÄڴ棬³ÌÐòÔ±×Ô¼º¸ºÔðÔÚºÎʱÓÃfree »òdelete ÊÍ·ÅÄÚ´æ¡£¶¯Ì¬ÄÚ´æµÄÉú´æÆÚ
ÓÉÎÒÃǾö¶¨£¬Ê¹Ó÷dz£Áé»î£¬µ«ÎÊÌâÒ²×î¶à¡£
void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str£¬ "hello world");
printf(str);
}
ÇëÎÊÔËÐÐTest º¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º³ÌÐò±ÀÀ£¡£
ÒòΪGetMemory ²¢²»ÄÜ´«µÝ¶¯Ì¬Äڴ棬
Test º¯ÊýÖÐµÄ str Ò»Ö±¶¼ÊÇ NULL¡£
strcpy(str£¬ "hello world");½«Ê¹³ÌÐò±À
À£¡£
char *GetMemory(void)
{
char p[] = "hello world";
return p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);
}
ÇëÎÊÔËÐÐTest º¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º¿ÉÄÜÊÇÂÒÂë¡£
ÒòΪGetMemory ·µ»ØµÄÊÇÖ¸Ïò“Õ»ÄÚ´æ”
µÄÖ¸Õ룬¸ÃÖ¸ÕëµÄµØÖ·²»ÊÇ NULL£¬µ«ÆäÔ­
ÏÖµÄÄÚÈÝÒѾ­±»Çå³ý£¬ÐÂÄÚÈݲ»¿ÉÖª¡£
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 º¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º
£¨1£©Äܹ»Êä³öhello
£¨2£©ÄÚ´æÐ¹Â©
void Test(void)
{
char *str = (char *) malloc(100);
strcpy(str£¬ “hello”);
free(str);
if(str £¡= NULL)
{
strcpy(str£¬ “world”);
printf(str);
}
}
ÇëÎÊÔËÐÐTest º¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º´Û¸Ä¶¯Ì¬ÄÚ´æÇøµÄÄÚÈÝ£¬ºó¹ûÄÑÒÔÔ¤
ÁÏ£¬·Ç³£Î£ÏÕ¡£
ÒòΪfree(str);Ö®ºó£¬str ³ÉΪҰָÕ룬
if(str £¡= NULL)Óï¾ä²»Æð×÷Óá£
******************


Ïà¹ØÎĵµ£º

linux ÏÂÓÃCʵÏÖ¡®CAT¡¯µÄ¹¦ÄÜ

linux
ÏÂÓÃCʵÏÖ‘CAT’µÄ¹¦ÄÜ
#include<stdio.h>
int main(int argc,char *argv[]){
FILE *file;
char buf[1024],name[20];
int n;
if(argc != 2){
printf("wrong argument\n");
return 1;
}
file=fopen(argv[1],"r");
if(file==NULL){
printf("Cant't open!\n&quo ......

ɾ³ýC/C++×¢ÊÍ

/********************************************************************
*ɾ³ýC/C++×¢ÊÍ
**********************************************************************/
#include <stdio.h>
//×¢Òâ
//1.¶Ô/****/µÄ´¦Àí
//2.Òª±£ÁôË«ÒýºÅÖ®¼äµÄÄÚÈÝ£¬Èçchar* test = "/*i am not comment */";
//3.¶ÔÓ ......

c/sÓëb/sµÄ²»Í¬

C/SÊÇClient/ServerµÄËõд¡£·þÎñÆ÷ͨ³£²ÉÓøßÐÔÄܵÄPC¡¢¹¤×÷Õ¾»òСÐÍ»ú£¬²¢²ÉÓôóÐÍÊý¾Ý¿âϵͳ£¬ÈçOracle¡¢Sybase¡¢Informix»ò SQL Server¡£¿Í»§¶ËÐèÒª°²×°×¨ÓõĿͻ§¶ËÈí¼þ¡£
B/S ÊÇBrower/ServerµÄËõд£¬¿Í»§»úÉÏÖ»Òª°²×°Ò»¸öä¯ÀÀÆ÷£¨Browser£©£¬ÈçNetscape Navigator»òInternet Explorer£¬·þÎñÆ÷°²×°Oracle¡¢Sybase¡¢In ......

Boost Python ʵÏÖCµ÷ÓÃpython´íÎó½â¾ö·½·¨

ÓÉÓÚBoost Python¸ú²»ÉÏPython°æ±¾¸üУ¬ÈçÏ·½·¨µ÷ÓÿÉÄܲúÉúTypeError: 'NoneType' object does not support item assignmentÒì³£¡£
Boost PythonÎĵµÖÐÀý×Ó¿ÉÄܲúÉúÒì³£¡£
Py_Initialize();
object main_module = import("__main__");
object main_dict = main_module.attr("__dict__");
try{
   object ......

C±ê×¼¿âÔ´Âë½âÆÊ(14)£ºÍ¨Óú¯Êýstdlib.h

    ͨÓú¯Êý¿âÔÚÍ·Îļþstdlib.hÖÐÉùÃ÷£¬±È½ÏÅÓ´ó£¬Ö÷Òª·ÖΪÒÔϼ¸´óÀࣺ´æ´¢·ÖÅä¡¢Ëæ»úÊýÉú³É¡¢Êý×Öת»»ÓëÕûÐÍÔËËã¡¢³ÌÐòÍ˳öÓë»·¾³Í¨ÐÅ¡¢ËÑË÷ÓëÅÅÐò¡¢¶à×Ö½ÚÓë¿í×Ö·ûµÄת»»¡£ÓÉÓÚ¼³¼°µ½´æ´¢·ÖÅä¡¢»·¾³Í¨Ðŵȣ¬Òò´ËËüÃǵĴó¶àÊýÒ²ÒÀÀµÓÚ²Ù×÷ϵͳ¡£glibcÖУ¬Í¨Óú¯Êý¿âµÄºËÐÄʵÏÖÔÚstdlibºÍmallocÁ½¸öĿ¼Ï ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ