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

C³ÌÐò£ºÈ·¶¨Ò»¸öÕûÊýµÄ¼ÆËã»úÄÚ²¿±íʾÖÐÓм¸¸ö"1"

/*
×¢Òâ²»¶ÏÓÒÒÆÅжÏ×îµÍλÊÇ1ÓжàÉÙ¸öµÄËã·¨ÊÇ´íÎóµÄ£¬
ÒòΪ¸ù¾ÝGNU C/C++µÄʵÏÖÀ´¿´£¬¸ºÊýÊÇ´ø·ûºÅÌî³ä½øÐÐÓÒÒƵģ¬ËùÒÔÈç¹ûÊǸºÊý£¬¸ÃËã·¨»áËÀÑ­»·¡£
±äͨ°ì·¨£ºJava¿ÉÒÔÓÃ>>>Âß¼­ÓÒÒÆλ²Ù×÷·û£¬C/C++¿ÉÒÔÇ¿ÖÆת»»³ÉÎÞ·ûºÅÕûÊýÔÙ´¦Àí
ÏÂÃæµÄ³ÌÐòÊÇÕý½â¡£ÆäÖÐnum &= (num - 1) »áÏû³ýnumµÄ×îСλÖõÄ"1"
*/
#include <stdio.h>
int numOnesInBinary(int num)
{
int numOnes = 0;
while (num != 0) {
num &= (num - 1);
numOnes++;
}
return numOnes;
}
int main()
{
printf("%d", numOnesInBinary(-1));
return 0;
}


Ïà¹ØÎĵµ£º

CÍ·ÎļþÏ໥°üº¬µÄÎÊÌâ

     ÔÚC++ÖУ¬¹ØÓÚCPPµÄÍ·Îļþ»¥Ïà°üº¬µÄÎÊÌâºÜÈÃÈËÍ·ÌÛ£¬ÆäʵÎÒÃÇË­Ò²²»Ô¸ÒâŪµÄ½á¹¹»ìÂÒ£¬ÄÑÒÔÀí½â£¬µ«ÓÐʱÓÖÊÇÓбØÐëµÄ¡£
     ¼Ù¶¨µ±Ç°ÓÐÁ½¸öÍ·Îļþ·Ö±ðΪ A.h  ºÍ B.h£¬ÄÚÈÝ·Ö±ðÈçÏ£º
     A.hÄÚÈÝΪ£º
     #ifndef  ......

C/C++ ³ÌÐòÉè¼ÆԱӦƸ³£¼ûÃæÊÔÊÔÌâÉîÈëÆÊÎöÖ®Èý


ÊÔÌâ5£º±àдһ¸öº¯Êý£¬×÷ÓÃÊÇ°ÑÒ»¸öchar×é³ÉµÄ×Ö·û´®Ñ­»·ÓÒÒÆn¸ö¡£±ÈÈçÔ­À´ÊÇ“abcdefghi”Èç¹ûn=2£¬ÒÆλºóÓ¦¸ÃÊÇ“hiabcdefgh” 
¡¡¡¡º¯ÊýÍ·ÊÇÕâÑùµÄ£º
//pStrÊÇÖ¸ÏòÒÔ'\0'½áβµÄ×Ö·û´®µÄÖ¸Õë
//stepsÊÇÒªÇóÒƶ¯µÄn
void LoopMove ( char * pStr, int steps )
{
¡¡//ÇëÌî³ä...
}
¡¡¡¡½ ......

GNU C __attribute__ »úÖƼò½é

ͻ񻣼
ÔÚѧϰlinuxÄں˴úÂ뼰һЩ¿ªÔ´Èí¼þµÄÔ´Â루È磺DirectFB£©£¬¾­³£¿ÉÒÔ¿´µ½ÓйØ
__attribute__µÄÏà¹ØʹÓᣱ¾ÎĽáºÏ×Ô¼ºµÄѧϰ¾­Àú£¬½ÏΪÏêϸµÄ½éÉÜÁË__attribute__
Ïà¹ØÓï·¨¼°ÆäʹÓá£
---------------------------------------------------------
ÉùÃ÷£º
  ´ËÎÄΪԭ´´£¬»¶Ó­×ªÔØ£¬×ªÔØÇë±£ÁôÈçÏÂÐÅÏ¢
& ......

extern extern ¡°C¡±

externÊÇC/C++ÓïÑÔÖбíÃ÷º¯ÊýºÍÈ«¾Ö±äÁ¿×÷Ó÷¶Î§£¨¿É¼ûÐÔ£©.
Ëü¸æËß±àÒëÆ÷£¬ÆäÉùÃ÷µÄº¯ÊýºÍ±äÁ¿¿ÉÒÔÔÚ±¾Ä£¿é»òÆäËüÄ£¿éÖÐʹÓá£
1¡£¶ÔÓÚextern±äÁ¿À´Ëµ£¬½ö½öÊÇÒ»¸ö±äÁ¿µÄÉùÃ÷£¬Æä²¢²»ÊÇÔÚ¶¨Òå·ÖÅäÄÚ´æ¿Õ¼ä¡£Èç¹û¸Ã±äÁ¿¶¨Òå¶à´Î£¬»áÓÐÁ¬½Ó´íÎó
2¡£Í¨³££¬ÔÚÄ£¿éµÄÍ·ÎļþÖжԱ¾Ä£¿éÌṩ¸øÆäËüÄ£¿éÒýÓõĺ¯ÊýºÍ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ