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

C/C++ ±ÊÊÔ¡¢ÃæÊÔÌâÄ¿´ó»ã×Ü


1.ÇóÏÂÃ溯ÊýµÄ·µ»ØÖµ£¨ ΢Èí£©
int func(x)
{
    int countx = 0;
    while(x)
    {
          countx ++;
          x = x&(x-1);
     }
    return countx;

¼Ù¶¨x = 9999¡£ ´ð°¸£º8
˼·£º½«xת»¯Îª2½øÖÆ£¬¿´º¬ÓеÄ1µÄ¸öÊý¡£
2. ʲôÊÇ“ÒýÓÔ£¿ÉêÃ÷ºÍʹÓÓÒýÓÔҪעÒâÄÄЩÎÊÌ⣿
´ð£ºÒýÓþÍÊÇij¸öÄ¿±ê±äÁ¿µÄ“±ðÃû”(alias)£¬¶ÔÓ¦ÓõIJÙ×÷Óë¶Ô±äÁ¿Ö±½Ó²Ù×÷Ч¹ûÍêÈ«Ïàͬ¡£ÉêÃ÷Ò»¸öÒýÓõÄʱºò£¬ÇмÇÒª¶ÔÆä½øÐгõʼ»¯¡£ÒýÓÃÉùÃ÷Íê±Ïºó£¬Ï൱ÓÚÄ¿±ê±äÁ¿ÃûÓÐÁ½¸öÃû³Æ£¬¼´¸ÃÄ¿±êÔ­Ãû³ÆºÍÒýÓÃÃû£¬²»ÄÜÔٰѸÃÒýÓÃÃû×÷ΪÆäËû±äÁ¿ÃûµÄ±ðÃû¡£ÉùÃ÷Ò»¸öÒýÓ㬲»ÊÇж¨ÒåÁËÒ»¸ö±äÁ¿£¬ËüÖ»±íʾ¸ÃÒýÓÃÃûÊÇÄ¿±ê±äÁ¿ÃûµÄÒ»¸ö±ðÃû£¬Ëü±¾Éí²»ÊÇÒ»ÖÖÊý¾ÝÀàÐÍ£¬Òò´ËÒýÓñ¾Éí²»Õ¼´æ´¢µ¥Ôª£¬ÏµÍ³Ò²²»¸øÒýÓ÷ÖÅä´æ´¢µ¥Ôª¡£²»Äܽ¨Á¢Êý×éµÄÒýÓá£
3. ½«“ÒýÓÔ×÷Ϊº¯Êý²ÎÊýÓÐÄÄЩÌص㣿
£¨1£©´«µÝÒýÓøøº¯ÊýÓë´«µÝÖ¸ÕëµÄЧ¹ûÊÇÒ»ÑùµÄ¡£Õâʱ£¬±»µ÷º¯ÊýµÄÐβξͳÉΪԭÀ´Ö÷µ÷º¯ÊýÖеÄʵ²Î±äÁ¿»ò¶ÔÏóµÄÒ»¸ö±ðÃûÀ´Ê¹Óã¬ËùÒÔÔÚ±»µ÷º¯ÊýÖжÔÐβαäÁ¿µÄ²Ù×÷¾ÍÊǶÔÆäÏàÓ¦µÄÄ¿±ê¶ÔÏó£¨ÔÚÖ÷µ÷º¯ÊýÖУ©µÄ²Ù×÷¡£
£¨2£©Ê¹ÓÃÒýÓô«µÝº¯ÊýµÄ²ÎÊý£¬ÔÚÄÚ´æÖв¢Ã»ÓвúÉúʵ²ÎµÄ¸±±¾£¬ËüÊÇÖ±½Ó¶Ôʵ²Î²Ù×÷£»¶øʹÓÃÒ»°ã±äÁ¿´«µÝº¯ÊýµÄ²ÎÊý£¬µ±·¢Éúº¯Êýµ÷ÓÃʱ£¬ÐèÒª¸øÐβηÖÅä´æ´¢µ¥Ôª£¬ÐβαäÁ¿ÊÇʵ²Î±äÁ¿µÄ¸±±¾£»Èç¹û´«µÝµÄÊǶÔÏ󣬻¹½«µ÷Óÿ½±´¹¹Ô캯Êý¡£Òò´Ë£¬µ±²ÎÊý´«µÝµÄÊý¾Ý½Ï´óʱ£¬ÓÃÒýÓñÈÓÃÒ»°ã±äÁ¿´«µÝ²ÎÊýµÄЧÂʺÍËùÕ¼¿Õ¼ä¶¼ºÃ¡£
£¨3£©Ê¹ÓÃÖ¸Õë×÷Ϊº¯ÊýµÄ²ÎÊýËäȻҲÄÜ´ïµ½ÓëʹÓÃÒýÓõÄЧ¹û£¬µ«ÊÇ£¬ÔÚ±»µ÷º¯ÊýÖÐͬÑùÒª¸øÐβηÖÅä´æ´¢µ¥Ôª£¬ÇÒÐèÒªÖظ´Ê¹ÓÃ"*Ö¸Õë±äÁ¿Ãû"µÄÐÎʽ½øÐÐÔËË㣬ÕâºÜÈÝÒײúÉú´íÎóÇÒ³ÌÐòµÄÔĶÁÐԽϲÁíÒ»·½Ã棬ÔÚÖ÷µ÷º¯ÊýµÄµ÷Óõ㴦£¬±ØÐëÓñäÁ¿µÄµØÖ·×÷Ϊʵ²Î¡£¶øÒýÓøüÈÝÒ×ʹÓ㬸üÇåÎú¡£
4. ÔÚʲôʱºòÐèҪʹÓÓ³£ÒýÓÔ£¿¡¡
Èç¹û¼ÈÒªÀûÓÃÒýÓÃÌá¸ß³ÌÐòµÄЧÂÊ£¬ÓÖÒª±£»¤´«µÝ¸øº¯ÊýµÄÊý¾Ý²»ÔÚº¯ÊýÖб»¸Ä±ä£¬¾ÍӦʹÓó£ÒýÓᣳ£ÒýÓÃÉùÃ÷·½Ê½£ºconst ÀàÐͱêʶ·û &ÒýÓÃÃû=Ä¿±ê±äÁ¿Ãû£»
Àý1
int a ;
const int &ra=a;
ra=1; //´íÎó
a=1; //ÕýÈ·
Àý2
string


Ïà¹ØÎĵµ£º

Ò»·ÝC/S½çÃæ¹æ·¶

1. ½çÃæ¹æ·¶
1.1. ×ÜÌåÔ­Ôò
l ÒÔÓû§ÎªÖÐÐÄ¡£Éè¼ÆÓÉÓû§¿ØÖƵĽçÃ棬¶ø²»ÊǽçÃæ¿ØÖÆÓû§¡£
l Çå³þÒ»ÖµÄÉè¼Æ¡£ËùÓнçÃæµÄ·ç¸ñ±£³ÖÒ»Ö£¬ËùÓоßÓÐÏàͬº¬ÒåµÄÊõÓï±£³ÖÒ»Ö£¬ÇÒÒ×ÓÚÀí½â
l ÓµÓÐÁ¼ºÃµÄÖ±¾õÌØÕ÷¡£ÒÔÓû§ËùÊìϤµÄÏÖʵÊÀ½çÊÂÎñµÄ³éÏóÀ´¸øÓû§°µÊ¾ºÍÒþÓ÷£¬À´°ïÖúÓû§ÄÜѸËÙѧ»áÈí¼þµÄʹÓá£
l ½Ï¿ìµÄÏìÓ¦Ë ......

C³ÌÐòÔ±µÄÇéÊé

#include <stdio.h>
#include <string.h>
int
main(void)
{
char str[] =
"3BVPSq4xF.K?=u#,"
"G'K<MrDnRr7gH%#,"
"XKf<f%G`w^=?C<#,"
"HgU_AnNR?*PDQU#,"
......

c³ÌÐòÉè¼ÆÓïÑÔÏ°Ìâ1 9

ÁªÏµ1-9±àдһ¸ö½«ÊäÈ븴ÖƵ½Êä³öµÄ³ÌÐò£¬²¢½«ÆäÖÐÁ¬ÐøµÄ¶à¸ö¿Õ¸ñÓÃÒ»¸ö¿Õ¸ñ´úÌæ¡£
#include "stdio.h"
main(){
int c;
int flag;
flag=0;//ÊÇ·ñ¿Õ¸ñ±êÖ¾
while ((c=getchar())!=EOF){
if (c!=32) {
putchar(c);
flag=0;
}else if(flag==0){
flag=1;
putchar(c);
}

/* ......

¡¾×ª¡¿CµÄÁíÒ»ÖØÒªÊý¾Ý½á¹¹bit fields

½ñÌì¿´K&RµÄÊéµÄʱºò˳±ãÎÂÏ°ÁËCµÄÁíÒ»ÖØÒªÊý¾Ý½á¹¹bit-fields£¬ÎÒÏëbit-fieldsÔÚ±àдµ×²ãÇý¶¯
Çý¶¯³ÌÐòµÄʱºòÓ¦¸Ã±È½ÏºÃÓã¬Ëü¿ÉÒÔÈÆ¿ª"&"ºÍ"|"½øÐÐλ²Ù×÷£¬¶øÇÒ¸ü¼Ó½ÚÔ¼ÄÚ´æ¿Õ¼ä¡£·Ï»°²»¶à˵
ÁË£¬»¹ÊÇÏÈÀ´¿´¿´ËüµÄÕæÃæÄ¿°É£º
bit-fieldÀ´Ô´:
bit-fieldÊÇΪÁ˽ÚÔ¼´æ´¢¿Õ¼ä¶ø´´ÔìµÄÒ»ÖÖÊý¾ ......

C/C++ ±ÊÊÔ¡¢ÃæÊÔÌâÄ¿´ó»ã×Ü£¨×ª£©

1.ÊDz»ÊÇÒ»¸ö¸¸ÀàдÁËÒ»¸övirtual º¯Êý£¬Èç¹û×ÓÀา¸ÇËüµÄº¯Êý²»¼Óvirtual ,Ò²ÄÜʵÏÖ¶à̬?
virtualÐÞÊηû»á±»ÒþÐμ̳еġ£private Ò²±»¼¯³É£¬Ö»ÊÂÅÉÉúÀàûÓзÃÎÊȨÏÞ¶øÒÑ¡£virtual¿É¼Ó¿É²»¼Ó¡£×ÓÀàµÄ¿Õ¼äÀïÓи¸ÀàµÄËùÓбäÁ¿(static³ýÍâ)¡£Í¬Ò»¸öº¯ÊýÖ»´æÔÚÒ»¸öʵÌå(inline³ýÍâ)¡£×ÓÀา¸ÇËüµÄº¯Êý²»¼Óvirtual ,Ò²ÄÜʵÏÖ¶àÌ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ