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

TOP

º¼ÖÝ-Ìì³±Íø¸ñϵͳÉ豸¹¤³ÌÓÐÏÞ¹«Ë¾
2014-11-24 01:40:41 ¡¾´ó ÖРС¡¿ ä¯ÀÀ:346´Î
Tags£ºº¼ÖÝ Íø¸ñ ϵͳ É豸 ¹¤³Ì ÓÐÏÞ¹«Ë¾

1.·Ö±ðд³öBOOL,int,float,Ö¸ÕëÀàÐ͵ıäÁ¿a Óë¡°Á㡱µÄ±È½ÏÓï¾ä¡£
´ð°¸£º
BOOL : if ( !a ) or if(a)
int : if ( a == 0)
float : const EXPRESSION EXP = 0.000001
if ( a < EXP && a >-EXP)
pointer : if ( a != NULL) or if(a == NULL)


2.Çë˵³öconstÓë#define Ïà±È£¬ÓкÎÓŵ㣿
´ð°¸£º1£© const ³£Á¿ÓÐÊý¾ÝÀàÐÍ£¬¶øºê³£Á¿Ã»ÓÐÊý¾ÝÀàÐÍ¡£±àÒëÆ÷¿ÉÒÔ¶ÔÇ°Õß½øÐÐÀàÐÍ°²È«¼ì²é¡£¶ø¶ÔºóÕßÖ»½øÐÐ×Ö·ûÌæ»»£¬Ã»ÓÐÀàÐÍ°²È«¼ì²é£¬²¢ÇÒÔÚ×Ö·ûÌæ»»¿ÉÄÜ»á²úÉúÒâÁϲ»µ½µÄ´íÎó¡£
2£© ÓÐЩ¼¯³É»¯µÄµ÷ÊÔ¹¤¾ß¿ÉÒÔ¶Ôconst ³£Á¿½øÐе÷ÊÔ£¬µ«ÊDz»ÄܶԺ곣Á¿½øÐе÷ÊÔ¡£


3.¼òÊöÊý×éÓëÖ¸ÕëµÄÇø±ð£¿
Êý×éҪôÔÚ¾²Ì¬´æ´¢Çø±»´´½¨£¨ÈçÈ«¾ÖÊý×飩£¬ÒªÃ´ÔÚÕ»Éϱ»´´½¨¡£Ö¸Õë¿ÉÒÔËæʱָÏòÈÎÒâÀàÐ͵ÄÄÚ´æ¿é¡£
(1)ÐÞ¸ÄÄÚÈÝÉϵIJî±ð
char a[] = ¡°hello¡±;
a[0] = ¡®X¡¯;
char *p = ¡°world¡±; // ×¢Òâp Ö¸Ïò³£Á¿×Ö·û´®
p[0] = ¡®X¡¯; // ±àÒëÆ÷²»ÄÜ·¢ÏָôíÎó£¬ÔËÐÐʱ´íÎó
(2) ÓÃÔËËã·ûsizeof ¿ÉÒÔ¼ÆËã³öÊý×éµÄÈÝÁ¿£¨×Ö½ÚÊý£©¡£sizeof(p),p ΪָÕëµÃµ½µÄÊÇÒ»¸öÖ¸Õë±äÁ¿µÄ×Ö½ÚÊý£¬¶ø²»ÊÇp ËùÖ¸µÄÄÚ´æÈÝÁ¿¡£C++/C ÓïÑÔûÓа취֪µÀÖ¸ÕëËùÖ¸µÄÄÚ´æÈÝÁ¿£¬³ý·ÇÔÚÉêÇëÄÚ´æʱ¼ÇסËü¡£×¢Òâµ±Êý×é×÷Ϊº¯ÊýµÄ²ÎÊý½øÐд«µÝʱ£¬¸ÃÊý×é×Ô¶¯ÍË»¯ÎªÍ¬ÀàÐ͵ÄÖ¸Õë¡£
char a[] = ¡°hello world¡±;
char *p = a;
cout<< sizeof(a) << endl; // 12 ×Ö½Ú
cout<< sizeof(p) << endl; // 4 ×Ö½Ú
¼ÆËãÊý×éºÍÖ¸ÕëµÄÄÚ´æÈÝÁ¿
void Func(char a[100])
{
cout<< sizeof(a) << endl; // 4 ×Ö½Ú¶ø²»ÊÇ100 ×Ö½Ú
}


4.Àà³ÉÔ±º¯ÊýµÄÖØÔØ¡¢¸²¸ÇºÍÒþ²ØÇø±ð£¿
´ð°¸£º
a.³ÉÔ±º¯Êý±»ÖØÔصÄÌØÕ÷£º
£¨1£©ÏàͬµÄ·¶Î§£¨ÔÚͬһ¸öÀàÖУ©£»
£¨2£©º¯ÊýÃû×ÖÏàͬ£»
£¨3£©²ÎÊý²»Í¬£»
£¨4£©virtual ¹Ø¼ü×Ö¿ÉÓпÉÎÞ¡£
b.¸²¸ÇÊÇÖ¸ÅÉÉúÀຯÊý¸²¸Ç»ùÀຯÊý£¬ÌØÕ÷ÊÇ£º
£¨1£©²»Í¬µÄ·¶Î§£¨·Ö±ðλÓÚÅÉÉúÀàÓë»ùÀࣩ£»
£¨2£©º¯ÊýÃû×ÖÏàͬ£»
£¨3£©²ÎÊýÏàͬ£»
£¨4£©»ùÀຯÊý±ØÐëÓÐvirtual ¹Ø¼ü×Ö¡£
c.¡°Òþ²Ø¡±ÊÇÖ¸ÅÉÉúÀàµÄº¯ÊýÆÁ±ÎÁËÓëÆäͬÃûµÄ»ùÀຯÊý£¬¹æÔòÈçÏ£º
£¨1£©Èç¹ûÅÉÉúÀàµÄº¯ÊýÓë»ùÀàµÄº¯ÊýͬÃû£¬µ«ÊDzÎÊý²»Í¬¡£´Ëʱ£¬²»ÂÛÓÐÎÞvirtual¹Ø¼ü×Ö£¬»ùÀàµÄº¯Êý½«±»Òþ²Ø£¨×¢Òâ±ðÓëÖØÔØ»ìÏý£©¡£
£¨2£©Èç¹ûÅÉÉúÀàµÄº¯ÊýÓë»ùÀàµÄº¯ÊýͬÃû£¬²¢ÇÒ²ÎÊýÒ²Ïàͬ£¬µ«ÊÇ»ùÀຯÊýûÓÐvirtual ¹Ø¼ü×Ö¡£´Ëʱ£¬»ùÀàµÄº¯Êý±»Òþ²Ø£¨×¢Òâ±ðÓ븲¸Ç»ìÏý£©


5. There are two int variables: a and b, don¡¯t use ¡°if¡±, ¡° :¡±, ¡°switch¡±or other judgement statements, find out the biggest one of the two numbers.
´ð°¸£º( ( a + b ) + abs( a - b ) ) / 2


6. ÈçºÎ´òÓ¡³öµ±Ç°Ô´ÎļþµÄÎļþÃûÒÔ¼°Ô´ÎļþµÄµ±Ç°Ðкţ¿
´ð°¸£º
cout << __FILE__ ;
cout<<__LINE__ ;
__FILE__ºÍ__LINE__ÊÇϵͳԤ¶¨Òåºê£¬ÕâÖֺ겢²»ÊÇÔÚij¸öÎļþÖж¨ÒåµÄ£¬¶øÊÇÓɱàÒëÆ÷¶¨ÒåµÄ¡£


7. main Ö÷º¯ÊýÖ´ÐÐÍê±Ïºó£¬ÊÇ·ñ¿ÉÄÜ»áÔÙÖ´ÐÐÒ»¶Î´úÂ룬¸ø³ö˵Ã÷£¿
´ð°¸£º¿ÉÒÔ£¬¿ÉÒÔÓÃ_onexit ×¢²áÒ»¸öº¯Êý£¬Ëü»áÔÚmain Ö®ºóÖ´ÐÐint fn1(void), fn2(void), fn3(void), fn4 (void);
void main( void )
{
String str("zhanglin");
_onexit( fn1 );
_onexit( fn2 );
_onexit( fn3 );
_onexit( fn4 );
printf( "This is executed first.\n" );
}
int fn1()
{
printf( "next.\n" );
return 0;
}
int fn2()
{
printf( "executed " );
return 0;
}
int fn3()
{
printf( "is " );
return 0;
}
int fn4()
{
printf( "This " );
return 0;
}
The _onexit function is passed the address of a function (func) to be called when the program terminates normally. Successive calls to _onexit create a register of functions that are executed in LIFO (last-in-first-out) order. The functions passed to _onexit cannot take parameters.


8. ÈçºÎÅжÏÒ»¶Î³ÌÐòÊÇÓÉC ±àÒë³ÌÐò»¹ÊÇÓÉC++±àÒë³ÌÐò±àÒëµÄ£¿
´ð°¸£º
#ifdef __cplusplus
cout<<"c++";
#else
cout<<"c";
#endif


9.ÎļþÖÐÓÐÒ»×éÕûÊý£¬ÒªÇóÅÅÐòºóÊä³öµ½ÁíÒ»¸öÎļþÖÐ
´ð°¸£º


££i nclude


££i nclude


using namespace std;


void Order(vector& data) //bubble sort
{
int count = data.size() ;
int tag = false ; // ÉèÖÃÊÇ·ñÐèÒª¼ÌÐøðÅݵıê־λ
for ( int i = 0 ; i < count ; i++)
{
for ( int j = 0 ; j < count - i - 1 ; j++)
{
if ( data[j] > data[j+1])
{
tag = true ;
int temp = data[j] ;
data[j] = data[j+1] ;
data[j+1] = temp ;
}
}
if ( !tag )
break ;
}
}


void main( void )
{
vectordata;
ifstream in(¡°c:\\data.txt¡±);
if ( !in)
{
cout<<"file error!";
exit(1);
}
int temp;
while (!in.eof())
{
in>>temp;
data.push_back(temp);
}
in.close(); //¹Ø±ÕÊäÈëÎļþÁ÷
Order(data);
ofstream out(¡°c:\\result.txt¡±);
if ( !out)
{
cout<<"file error!";
exit(1);
}
for ( i = 0 ; i < data.size() ; i++)
out< 10. Á´±íÌ⣺һ¸öÁ´±íµÄ½áµã½á¹¹
struct Node
{
int data ;
Node *next ;
};
typedef struct Node Node ;


(1)ÒÑÖªÁ´±íµÄÍ·½áµãhead,дһ¸öº¯Êý°ÑÕâ¸öÁ´±íÄæÐò ( Intel)


Node * ReverseList(Node *head) //Á´±íÄæÐò
{
if ( head == NULL || head->next == NULL )
return head;
Node *p1 = head ;
Node *p2 = p1->next ;
Node *p3 = p2->next ;
p1->next = NULL ;
while ( p3 != NULL )
{
p2->next = p1 ;
p1 = p2 ;
p2 = p3 ;
p3 = p3->next ;
}
p2->next = p1 ;
head = p2 ;
return head ;
}
(2)ÒÑÖªÁ½¸öÁ´±íhead1 ºÍhead2 ¸÷×ÔÓÐÐò£¬Çë°ÑËüÃǺϲ¢³ÉÒ»¸öÁ´±íÒÀÈ»ÓÐÐò¡£(±£ÁôËùÓнáµã£¬¼´±ã´óСÏàͬ£©
Node * Merge(Node *head1 , Node *head2)
{
if ( head1 == NULL)
return head2 ;
if ( head2 == NULL)
return head1 ;
Node *head = NULL ;
Node *p1 = NULL;
Node *p2 = NULL;
if ( head1->data < head2->data )
{
head = head1 ;
p1 = head1->next;
p2 = head2 ;
}
else
{
head = head2 ;
p2 = head2->next ;
p1 = head1 ;
}
Node *pcurrent = head ;
while ( p1 != NULL && p2 != NULL)
{
if ( p1->data <= p2->data )
{
pcurrent->next = p1 ;
pcurrent = p1 ;
p1 = p1->next ;
}
else
{
pcurrent->next = p2 ;
pcurrent = p2 ;
p2 = p2->next ;
}
}
if ( p1 != NULL )
pcurrent->next = p1 ;
if ( p2 != NULL )
pcurrent->next = p2 ;
return head ;
}
(3)ÒÑÖªÁ½¸öÁ´±íhead1 ºÍhead2 ¸÷×ÔÓÐÐò£¬Çë°ÑËüÃǺϲ¢³ÉÒ»¸öÁ´±íÒÀÈ»ÓÐÐò£¬Õâ´ÎÒªÇóÓõݹ鷽·¨½øÐС£ (Autodesk)
´ð°¸£º
Node * MergeRecursive(Node *head1 , Node *head2)
{
if ( head1 == NULL )
return head2 ;
if ( head2 == NULL)
return head1 ;
Node *head = NULL ;
if ( head1->data < head2->data )
{
head = head1 ;
head->next = MergeRecursive(head1->next,head2);
}
else
{
head = head2 ;
head->next = MergeRecursive(head1,head2->next);
}
return head ;
}


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
ÉÏһƪ£º°´×ÔÈ»ÐòÁжÔÊý×ÖÊý×é½øÐÐÅÅÐòºÍ.. ÏÂһƪ£º¸ñ·½&ʱ´ú½Ü³ÏJava¿ª·¢¹¤³ÌʦÃæÊÔ..

×îÐÂÎÄÕÂ

ÈÈÃÅÎÄÕÂ

Hot ÎÄÕÂ

Python

C ÓïÑÔ

C++»ù´¡

´óÊý¾Ý»ù´¡

linux±à³Ì»ù´¡

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