C/C++ ±ÊÊÔ¡¢ÃæÊÔÌâÄ¿´ó»ã×Ü(1)
һλͬѧÕûÀíµÄ³£¼û±ÊÊÔ/ÃæÊÔÌâÄ¿£¬´ð°¸½ö¹©²Î¿¼£¬²»´ú±í±¾È˹۵㡣
Õâ¸ö¶«Î÷ÓÐЩ²Î¿¼¼ÛÖµ,ºÍͬѧÌÖÂÛһϷ¢ÏÖ»¹ÊÇÓÐЩ´íÎó,
1£®ÒÑÖªstrcpyº¯ÊýµÄÔÐÍÊÇ£º
char * strcpy(char * strDest,const char * strSrc);
1.²»µ÷Óÿ⺯Êý£¬ÊµÏÖstrcpyº¯Êý¡£
2.½âÊÍΪʲôҪ·µ»Øchar *¡£
½â˵£º
1.strcpyµÄʵÏÖ´úÂë
char * strcpy(char * strDest,const char * strSrc)
{
if ((strDest==NULL)||(strSrc==NULL)) //[1]
throw "Invalid argument(s)"; //[2]
char * strDestCopy=strDest; //[3]
while ((*strDest++=*strSrc++)!='\0'); //[4]
return strDestCopy;
}
´íÎóµÄ×ö·¨£º
[1]
(A)²»¼ì²éÖ¸ÕëµÄÓÐЧÐÔ£¬ËµÃ÷´ðÌâÕß²»×¢ÖØ´úÂëµÄ½¡×³ÐÔ¡£
(B)¼ì²éÖ¸ÕëµÄÓÐЧÐÔʱʹÓÃ((!strDest)||(!strSrc))»ò(!(strDest&&strSrc))£¬ËµÃ÷´ðÌâÕ߶ÔCÓïÑÔÖÐÀàÐ͵ÄÒþʽת»»Ã»ÓÐÉî¿ÌÈÏʶ¡£ÔÚ±¾ÀýÖÐchar *ת»»Îªbool¼´ÊÇÀàÐÍÒþʽת»»£¬ÕâÖÖ¹¦ÄÜËäÈ»Áé»î£¬µ«¸ü¶àµÄÊǵ¼Ö³ö´í¸ÅÂÊÔö´óºÍά»¤³É±¾Éý¸ß¡£ËùÒÔC++רÃÅÔö¼ÓÁËbool¡¢true¡¢falseÈý¸ö¹Ø¼ü×ÖÒÔÌṩ¸ü°²È«µÄÌõ¼þ±í´ïʽ¡£
(C)¼ì²éÖ¸ÕëµÄÓÐЧÐÔʱʹÓÃ((strDest==0)||(strSrc==0))£¬ËµÃ÷´ðÌâÕß²»ÖªµÀʹÓó£Á¿µÄºÃ´¦¡£Ö±½ÓʹÓÃ×ÖÃæ³£Á¿£¨Èç±¾ÀýÖеÄ0£©»á¼õÉÙ³ÌÐòµÄ¿Éά»¤ÐÔ¡£0ËäÈ»¼òµ¥£¬µ«³ÌÐòÖпÉÄܳöÏֺܶദ¶ÔÖ¸ÕëµÄ¼ì²é£¬ÍòÒ»³öÏÖ±ÊÎ󣬱àÒëÆ÷²»ÄÜ·¢ÏÖ£¬Éú³ÉµÄ³ÌÐòÄÚº¬Âß¼´íÎ󣬺ÜÄÑÅųý¡£¶øʹÓÃNULL´úÌæ0£¬Èç¹û³öÏÖƴд´íÎ󣬱àÒëÆ÷¾Í»á¼ì²é³öÀ´¡£
[2]
(A)return new string("Invalid argument(s)");£¬ËµÃ÷´ðÌâÕ߸ù±¾²»ÖªµÀ·µ»ØÖµµÄÓÃ;£¬²¢ÇÒËû¶ÔÄÚ´æй©ҲûÓо¯ÌèÐÄ¡£´Óº¯ÊýÖзµ»Øº¯ÊýÌåÄÚ·ÖÅäµÄÄÚ´æÊÇÊ®·ÖΣÏÕµÄ×ö·¨£¬Ëû°ÑÊÍ·ÅÄÚ´æµÄÒåÎñÅ׸ø²»ÖªÇéµÄµ÷ÓÃÕߣ¬¾ø´ó¶àÊýÇé¿öÏ£¬µ÷ÓÃÕß²»»áÊÍ·ÅÄڴ棬Õâµ¼ÖÂÄÚ´æй©¡£
(B)return 0;£¬ËµÃ÷´ðÌâÕßûÓÐÕÆÎÕÒì³£»úÖÆ¡£µ÷ÓÃÕßÓпÉÄÜÍü¼Ç¼ì²é·µ»ØÖµ£¬µ÷ÓÃÕß»¹¿ÉÄÜÎÞ·¨¼ì²é·µ»ØÖµ£¨¼ûºóÃæµÄÁ´Ê½±í´ïʽ£©¡£ÍýÏëÈ÷µ»ØÖµ¼ç¸º·µ»ØÕýÈ·ÖµºÍÒì³£ÖµµÄË«Öع¦ÄÜ£¬Æä½á¹ûÍùÍùÊÇÁ½ÖÖ¹¦Äܶ¼Ê§Ð§¡£Ó¦¸ÃÒÔÅ׳öÒì³£À´´úÌæ·µ»ØÖµ£¬ÕâÑù¿ÉÒÔ¼õÇáµ÷ÓÃÕߵĸºµ£¡¢Ê¹´íÎ󲻻ᱻºöÂÔ¡¢ÔöÇ¿³ÌÐòµÄ¿Éά»¤ÐÔ¡£
[3]
(A)Íü¼Ç±£´æÔʼµÄstrDestÖµ£¬ËµÃ÷´ðÌâÕßÂ߼˼ά²»ÑÏÃÜ¡£
[4]
(A)Ñ»·Ð´³Éwhile (*strDest++=*strSrc++);£¬Í¬[1](B)¡£
(B)Ñ»·Ð´³Éwhile (*strSrc!='\0') *strDest++=*strSrc++;£¬ËµÃ÷´ðÌâÕ߶Ա߽çÌõ¼þµÄ¼ì²é²»Á¦¡£Ñ»·Ìå½áÊøºó£¬strDest×Ö·û´®µÄĩβûÓÐÕ
Ïà¹ØÎĵµ£º
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include ".\sqlite3_lib\sqlite3.h"
static int _callback_exec(void * notused,int argc, char ** argv, char ** aszColName)
{
int i;
for ( i=0; i<argc; i++ )
......
Delphi Óë C/C++ Êý¾ÝÀàÐͶÔÕÕ±í
DelphiÊý¾ÝÀàÐÍC/C++
ShorInt
8λÓзûºÅÕûÊý
char
Byte
8λÎÞ·ûºÅÕûÊý
BYTE,unsigned short
SmallInt
16λÓзûºÅÕûÊý
short
Word
16λÎÞ·ûºÅÕûÊý
unsigned short
Integer,LongInt
32λÓзûºÅÕûÊý
int,long
Cardinal,LongWord/DWORD
32λÎÞ·ûºÅÕûÊý
unsigned long
Int6 ......
1£©a = a + 5; Óë a += 5£»µÄÇø±ð¡£
¶þÕßÔÚ¹ãÒåÉÏÊǵȼۡ£D.Ritchie ÔÚCÓïÑÔÖÐÒýÈ븴ºÏÔËËã·ûµÄÖ÷ҪĿµÄÊÇΪÁËÌá¸ß±àÒëµÄЧÂÊÒÔ²úÉú¸ßÖÊÁ¿µÄÖ´ÐдúÂë¡£ÒòΪÕâЩÔËËã·ûµÄ¹¦ÄÜ»ù±¾É϶¼ÄÜÓÃÒ»¶þÌõ»úÆ÷Ö¸ÁîÀ´Íê³É¡£
2£©ÔÚC++ÖÐlong Óë int µÄÇø±ð
NameDescriptionSize*Range*
char
Character or s ......
»ªÎªC/C++±ÊÊÔÌâ2 ÊÕ²Ø
1. ij32λϵͳÏÂ, C++³ÌÐò£¬Çë¼ÆËãsizeof µÄÖµ
#include <stdio.h>
#include <malloc.h>
void Foo ( char str[100] )
{
printf("sizeof(str)=%d \n", sizeof(str) );//´Ë´¦Ê¹ÓÃchar *strÓëchar str[100]ÊÇÒ»ÑùµÄ£¬char str[100]²»Ö¸Ã÷´óС(char str[]) ......
Õâ¸öÌá·¨Óеã¹ÖÒ죬µ«»¹Êdz£³£³öÏÖ:
char *p = "abcd";
ºÍ
string str = "abcdefg";
µÚÒ»¸ö½Ð×öC·ç¸ñµÄ×Ö·û´®£¬ÔÒòÊÇÓÐnull×÷Ϊ½áβ; µÚ¶þ¸öΪC++·ç¸ñµÄ, ²»ÊÇÒÔnull½áβ.
ʵÖÊÉÏ: C·ç¸ñµÄ×Ö·û´®ÊÇ:
char[] pArr = {'a', 'b', 'c', 'd', '\0'};
ÕâÑù¾ö¶¨ÁË´¦Àí·½Ê½µÄ²»Í¬ ......