ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

º¼ÖÝ-ºã»ªÍøÂçVC++ÃæÊÔÌâ
2014-11-24 01:43:19 ¡¾´ó ÖРС¡¿ ä¯ÀÀ:5208´Î
Tags£ºº¼ÖÝ ºã»ª ÍøÂç ÊÔÌâ

Ò»¡¢ÇëÌîдBOOL , float, Ö¸Õë±äÁ¿ Óë¡°ÁãÖµ¡±±È½ÏµÄ if Óï¾ä¡££¨10·Ö£©
Ìáʾ£ºÕâÀï¡°ÁãÖµ¡±¿ÉÒÔÊÇ0, 0.0 , FALSE»òÕß¡°¿ÕÖ¸Õ롱¡£ÀýÈç int ±äÁ¿ n
Óë¡°ÁãÖµ¡±±È½ÏµÄ if Óï¾äΪ£º
if ( n == 0 )
if ( n != 0 )
ÒÔ´ËÀàÍÆ¡£
Çëд³ö BOOL flag Óë¡°ÁãÖµ¡±±È½ÏµÄ if Óï¾ä£º
Çëд³ö float x Óë¡°ÁãÖµ¡±±È½ÏµÄ if Óï¾ä£º
Çëд³ö char *p Óë¡°ÁãÖµ¡±±È½ÏµÄ if Óï¾ä£º
¶þ¡¢ÒÔÏÂΪWindows NTϵÄ32λC++³ÌÐò£¬Çë¼ÆËãsizeofµÄÖµ£¨10·Ö£©
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 ) =


Èý¡¢¼ò´ðÌ⣨25·Ö£©
1¡¢Í·ÎļþÖÐµÄ ifndef/define/endif ¸ÉʲôÓã¿
2¡¢#include ºÍ #include ¡°filename.h¡± ÓÐʲôÇø±ð£¿
3¡¢const ÓÐʲôÓÃ;£¿£¨ÇëÖÁÉÙ˵Ã÷Á½ÖÖ£©
4¡¢ÔÚC++ ³ÌÐòÖе÷Óñ» C±àÒëÆ÷±àÒëºóµÄº¯Êý£¬ÎªÊ²Ã´Òª¼Ó extern ¡°C¡±ÉùÃ÷£¿
5¡¢Çë¼òÊöÒÔÏÂÁ½¸öforÑ­»·µÄÓÅȱµã
// µÚÒ»¸ö
for (i=0; i
{
if (condition)
DoSomething();
else
DoOtherthing();
} // µÚ¶þ¸ö
if (condition)
{
for (i=0; i
DoSomething();
}
else
{
for (i=0; i
DoOtherthing();
}
Óŵ㣺
ȱµã£º
Óŵ㣺
ȱµã£º
ËÄ¡¢ÓйØÄÚ´æµÄ˼¿¼Ì⣨20·Ö£©
void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str, ¡°hello world¡±);
printf(str);
}
ÇëÎÊÔËÐÐTestº¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º


char *GetMemory(void)


{


char p[] = ¡°hello world¡±;


return p;


}


void Test(void)


{


char *str = NULL;


str = GetMemory();


printf(str);


}
ÇëÎÊÔËÐÐTestº¯Êý»áÓÐʲôÑùµÄ½á¹û£¿


´ð£º


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º¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º
void Test(void)
{
char *str = (char *) malloc(100);
strcpy(str, ¡°hello¡±);
free(str);
if(str != NULL)
{
strcpy(str, ¡°world¡±);
printf(str);
}
}
ÇëÎÊÔËÐÐTestº¯Êý»áÓÐʲôÑùµÄ½á¹û£¿


´ð£º
Îå¡¢±àдstrcpyº¯Êý£¨10·Ö£©
ÒÑÖªstrcpyº¯ÊýµÄÔ­ÐÍÊÇ
char *strcpy(char *strDest, const char *strSrc);
ÆäÖÐstrDestÊÇÄ¿µÄ×Ö·û´®£¬strSrcÊÇÔ´×Ö·û´®¡£
£¨1£©²»µ÷ÓÃC++/CµÄ×Ö·û´®¿âº¯Êý£¬Çë±àдº¯Êý strcpy
£¨2£©strcpyÄÜ°ÑstrSrcµÄÄÚÈݸ´ÖƵ½strDest£¬ÎªÊ²Ã´»¹Òªchar * ÀàÐ͵ķµ»ØÖµ£¿
Áù¡¢±àдÀàStringµÄ¹¹Ô캯Êý¡¢Îö¹¹º¯ÊýºÍ¸³Öµº¯Êý£¨25·Ö£©
ÒÑÖªÀàStringµÄÔ­ÐÍΪ£º
class String
{
public:
String(const char *str = NULL); // ÆÕͨ¹¹Ô캯Êý
String(const String &other); // ¿½±´¹¹Ô캯Êý
~ String(void); // Îö¹¹º¯Êý
String & operate =(const String &other); // ¸³Öµº¯Êý
private:
char *m_data; // ÓÃÓÚ±£´æ×Ö·û´®
};
Çë±àдStringµÄÉÏÊö4¸öº¯Êý¡£


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
ÉÏһƪ£ºJava»ù´¡ÖªÊ¶ÃæÊÔÌ⼯ºÏÏà¹ØµÄ¼ò.. ÏÂһƪ£ºÒ»¸öÖÐרÉúÔÚ»ªÎªÃæÊÔµÄÕæʵ¾­Àú

×îÐÂÎÄÕÂ

ÈÈÃÅÎÄÕÂ

Hot ÎÄÕÂ

Python

C ÓïÑÔ

C++»ù´¡

´óÊý¾Ý»ù´¡

linux±à³Ì»ù´¡

C/C++ÃæÊÔÌâÄ¿