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

C/C++ÓïÑÔÖÐÖ¸ÕëµÄÒâÒå

¿´µ½Õâ¸öÃæÊÔÌâ,¹À¼ÆºÜ¶à¸ÕѧCÖ¸ÕëµÄͬѧ¶¼»á¸ã´í.
void GetMemory(char *p)
{
// ´«µÝ½øÀ´µÄµÄֵʹµÃ*p==NULL
// ÕâÀïÐ޸ĵÄÊÇÕâ¸öº¯ÊýÄÚµÄÁÙʱָÕë±äÁ¿pµÄÖµ
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
// ´«µÝ½øÈ¥µÄÊÇstrµÄÖµNULL
GetMemory(str);
// ÕâÀïstrÖ¸Õ벢δ¸³Öµ,ÈÔÈ»ÊÇNULL,ËùÒÔÕâÀ︳ֵ»á³ö´í
strcpy(str, "Hello World");
printf("%s\n", str);
free(str);
}

ÎÒÃÇÖªµÀ¼ÆËã»úÖ»ÈÏʶ0ºÍ1,ËùÓеÄÊý¾Ý,°üÀ¨Í¼Æ¬,ÎÄ×ÖµÈ×îÖÕ¶¼ÊÇת»»³É0ºÍ1À´±íʾ.
ΪÁË·½±ã˵Ã÷,ÎÒÃÇÓÃÊ®Áù¸ö¶þ½øÖÆÊý×é³ÉµÄÒ»¸öÊ®Áù½øÖÆÊýÀ´±íʾ.
ÔÚwin32ϵͳÖÐ,ÄÚ´æµØÖ·ÊÇ´Ó0µ½2^32bit(Ï൱ÓÚ0µ½4GB),win32ÖÐVC6.0ÖÐÖ¸Õë±¾ÖʾÍÊÇÒ»¸öÕ¼4¸ö×Ö½ÚµÄÎÞ·ûºÅÕûÐÎ(unsigned int),ÄÜÈ¡0µ½2^32ÖÐËùÓеÄÖµµÄÈÎÒ»¸öÖµ,¼´Ö¸ÕëÄÜÏò¼ÆËã»úÄÚ´æÖÐÈκÎÒ»¸öµØÖ·.
// pCharÖ¸ÏòµÄÒ»¸öcharÐͱäÁ¿(×¢Òâ×Ö·ûºÍ×Ö·û´®¸ÅÄîÇø·Ö¿ª)
char *pChar = NULL;
// pIntÖ¸ÏòµÄÊÇÒ»¸öintÐͱäÁ¿
int *pInt = NULL;
// pDoubleÖ¸ÏòµÄÊÇÒ»¸öpDoubleÐͱäÁ¿
double *pDouble = NULL;
struct node
{
int i, j, k;
};
// pNodeÖ¸ÏòµÄÊÇÒ»¸ö×Ô¶¨Òå½á¹¹Ìå±äÁ¿
struct node *pNode = NULL;
class TestClass
{
TestClass()
{
}
~TestClass()
{
}
};
// pClassÖ¸ÏòµÄÊÇÒ»¸ö×Ô¶¨ÒåÀà±äÁ¿
TestClass *pClass = NULL;
void Test(void)
{
printf("This is test function!\n");
}
typedef void (*pFunction)(void);
// pFunÖ¸ÏòµÄÊÇÒ»¸öTestÐͺ¯Êý
pFunction pFun = Test;
void Test1(void)
{
printf("sizeof(pChar)=%d\n", sizeof(pChar));
printf("sizeof(pInt)=%d\n", sizeof(pInt));
printf("sizeof(pDouble)=%d\n", sizeof(pDouble));
printf("sizeof(pNode)=%d\n", sizeof(pNode));
printf("sizeof(pClass)=%d\n", sizeof(pClass));
printf("sizeof(pFun)=%d\n", sizeof(pFun));
}
´òÓ¡µÄ½á¹ûÈçÏÂ:
sizeof(pChar)=4
sizeof(pInt)=4
sizeof(pDouble)=4
sizeof(pNode)=4
sizeof(pClass)=4
sizeof(pFun)=4
Press any key to continue
ÉÏÃ涨ÒåµÄÖ¸ÕëºÍÆäËüϵͳÄܶ¨ÒåµÄËùÓÐÖ¸ÕëÔÚwin32ϵͳÖÐÓÃsizeof²âÊÔ¶¼ÊÇ4.
Ö¸ÕëÓÐʲôÇø±ðÄØ?
±ÈÈçchar *pCharºÍint *pInt:
pCharÖ»ÊǸæËß³ÌÐòÎ


Ïà¹ØÎĵµ£º

CÓïÑÔÎļþ

13.1 CÎļþ¸ÅÊö
    Ëùν“Îļþ”ÊÇÖ¸Ò»×éÏà¹ØÊý¾ÝµÄÓÐÐò¼¯ºÏ¡£Õâ¸öÊý¾Ý¼¯ÓÐÒ»¸öÃû³Æ£¬½Ð×öÎļþÃû¡£Êµ¼ÊÉÏÔÚÇ°ÃæµÄ¸÷ÕÂÖÐÎÒÃÇÒѾ­¶à´ÎʹÓÃÁËÎļþ£¬ÀýÈçÔ´³ÌÐòÎļþ¡¢Ä¿±êÎļþ¡¢¿ÉÖ´ÐÐÎļþ¡¢¿âÎļþ (Í·Îļþ)µÈ¡£
    Îļþͨ³£ÊÇפÁôÔÚÍⲿ½éÖÊ(Èç´ÅÅ̵È)Éϵģ¬ÔÚʹÓÃʱ²Åµ÷ÈëÄÚ´æÖ ......

Êý¾Ý½á¹¹ÔÚCÓïÑÔÖеÄÓ¦ÓÃ


     ÎÒÊÇÒ»¸ö¼ÆËã»úרҵµÄ±¾¿ÆÉú£¬ÏÖÔÚÎÒÃǸոÕѧÍêÁËÊý¾Ý½á¹¹¡£¾Ý˵Êý¾Ý½á¹¹¶ÔÓÚÎÒÃDZà³ÌºÜÖØÒª£¬¿ÉÊÇÎÒÏÖÔÚ²»ÖªÔõô°ÑÊý¾Ý½á¹¹ºÍCÓïÑÔ½áºÏÆðÀ´£¬ÒÔ±ã¸üºÃµÄ½øÐÐcÓïÑÔ±à³Ì¡£ÓÐÄÄλ¸ßÊÖÖ¸µãÒ»¶þ£¬ÔÚÏ¸м¤²»¾¡£¡
......

C/C++ ÈÕÆÚ Ê±¼ä time_tÓëstruct tmת»»

±¾ÎÄ´Ó½éÉÜ»ù´¡¸ÅÄîÈëÊÖ£¬Ì½ÌÖÁËÔÚC/C++ÖжÔÈÕÆÚºÍʱ¼ä²Ù×÷ËùÓõ½µÄÊý¾Ý½á¹¹ºÍº¯Êý£¬²¢¶Ô¼Æʱ¡¢Ê±¼äµÄ»ñÈ¡¡¢Ê±¼äµÄ¼ÆËãºÍÏÔʾ¸ñʽµÈ·½Ãæ½øÐÐÁ˲ûÊö¡£±¾ÎÄ»¹Í¨¹ý´óÁ¿µÄʵÀýÏòÄãչʾÁËtime.hÍ·ÎļþÖÐÉùÃ÷µÄ¸÷ÖÖº¯ÊýºÍÊý¾Ý½á¹¹µÄÏêϸʹÓ÷½·¨¡£
¹Ø¼ü×Ö£ºUTC£¨ÊÀ½ç±ê׼ʱ¼ä£©£¬Calendar Time£¨ÈÕÀúʱ¼ä£©£¬epoch£¨Ê±¼äµã£©£¬cl ......

¡¶The C Programming Language¡·µÚ¶þ´ÎÔĶÁÖ®ÊÕ»ñ

µÚÒ»Õ µ¼ÑÔ
    1£¬¶¨Òå(define)ÓëÉùÃ÷(declaration) 
    ¶¨Òå±íʾ´´½¨±äÁ¿»ò·ÖÅä´æ´¢µ¥Ôª£»¶øÉùÃ÷Ö¸µÄÊÇ˵Ã÷±äÁ¿µÄÐÔÖÊ£¬µ«²»·ÖÅä´æ´¢µ¥Ôª¡£
µÚ¶þÕ ÀàÐÍ¡¢ÔËËã·ûºÍ±í´ïʽ
    1£¬Êý¾ÝÀàÐͼ°³¤¶È
    CÖÐÖ»ÓÐ4ÖÖ»ù±¾Êý¾ÝÀàÐÍ£ºchar ,int ,float ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ