¹ØÓÚC/C++º¯ÊýÉùÃ÷ÖвÎÊý¸öÊýµÄÒÉÎÊ
ÎÄÕÂ×÷ÕߣºSlyar
ÏÈ¿´Á½¸ö´úÂ룬µÚÒ»¸öÊÇC³ÌÐò£¬µÚ¶þ¸öÊÇC++³ÌÐò£¬³ýÁËÍ·Îļþ²»Í¬ÒÔÍâÆäËûµÄ¶¼Ò»Ñù¡£
//demo.c
#include <stdio.h>
int foo();
int main()
{
int a;
foo(a);
return 0;
}
int foo(int a)
{
}//demo.cpp
#include <iostream>
int foo();
int main()
{
int a;
foo(a);
return 0;
}
int foo(int a)
{
}
½á¹ûÊÇC³ÌÐò±àÒë³É¹¦£¬C++³ÌÐò±àÒëʧ°Ü£¬Ìáʾº¯ÊýÉùÃ÷ºÍº¯Êý¶¨Òå²ÎÊýÁÐ±í²»·û...ÕâºÜÕý³££¬¹Ø¼üÊÇC³ÌÐòÔõô¿ÉÄܱàÒëͨ¹ý...ÎÒÖªµÀC¿ÉÒÔд¿É±ä²ÎÊýÁÐ±í£¬ÎÊÌâÊÇÎÒû¼ÓÄǸö"..."°¡£¬囧£¬¿´À´ÊDZàÒëÆ÷µÄÎÊÌâÁË£¬ÒòΪ´úÂëÒ»Ñù...
²éÁËһЩ¹úÍâµÄ×ÊÁÏ£¬´óÖÂÁ˽âÁËÉÏÃæÄǸöÎÊÌâµÄ³ÉÒò£¬Í¬Ê±Ò²ÖªµÀÁËf()ºÍf(void)µÄÇø±ð£¬Ö®Ç°Ò»Ö±ÒÔΪËûÃÇÊÇÒ»ÑùµÄ...
In C, the declaration int f(void) means a function returning int that takes no parameters.
ÔÚCÓïÑÔÖУ¬f(void)±íÃ÷º¯Êý·µ»ØÕûÐͲ¢ÇÒûÓÐÈκβÎÊý¡£
The declaration int f() means a function returning int that takes any number of parameters.(takes an unknown number of parameters of unknown types, giving it the wrong number results in undefined behavior. )
¶øf()±íÃ÷º¯Êý·µ»ØÕûÐͲ¢ÇÒ¿ÉÒÔʹÓÃÈÎÒâ¸öÊýµÄ²ÎÊý£¬µ«ÊÇËûµÄÐÐΪÊDz»È·¶¨µÄ¡£
ÓÉ´Ë¿ÉÒÔ¿´³ö£¬ÔÚCÓïÑÔÖÐÊÇÍƼöʹÓÃf(void)ÕâÖÖÐÎʽµÄ£¬ÒòΪËüÃ÷È·Ö¸Ã÷Á˺¯ÊýûÓвÎÊý£¬f()ÓÉÓÚ¿ÉÒÔʹÓÃÈÎÒâ¸öÊýµÄ²ÎÊý£¬µ±È»Ò²°üÀ¨Ã»ÓвÎÊý¡£
¶øÔÚC++ÖУ¬ÎÒÏëÊDz»ÍƼöʹÓÃf(void)ÕâÖÖÐÎʽµÄ£¬ÒòΪf()ÒѾÃ÷È·±íÃ÷ûÓÐÈκβÎÊýÁË¡£
Ïà¹ØÎĵµ£º
ÌýÆðÀ´£¬ÓÐ×ÔÐÅ£¬ÓиãЦ¡£ÓÖ×ÔÐÅ£¬ÓÖ¸ãЦ¡£
Á½ÄêÇ°£¬¿¼ÈëÁËÒ»¸ö¶þÁ÷´óѧ£¬·Ç¼ÆËã»úרҵ¡£µ±³õ»³×ÅÎÞ±ÈÃÀºÃµÄÐÄÇ飬ֻÊÇÏ£ÍûÔÚѧУ¹ýµÄ¿ìÀÖЩ£¬Ñ§µÄºÃЩ£¬µ«ÊÇÓÐЩÊÂÇé×ÜÊÇÄÑÒÔÔ¤ÁÏ£¬ÎÒ×ÜÊÇÎÞ·¨ÍüÈ´ÄÇ·Ý»³ÄÔÚÕâ¸öÄ°ÉúµÄ³ÇÊУ¬ÎÒ×ÜÊÇÃÔʧÁË×Ô¼º¡£Ä¬Ä¬µÄ¶ãÔÚ×Ô¼ºµÄÊÀ½çÀïÌòóÂÉË¿Ú£¬ÔÒÔΪµ½Á˸öеĻ·¾³ÄÜÍüµôÒ»ÇеÄÉËÐÄ¹Ê ......
1.ÄÚ´æ·ÖÅ䷽ʽ
¡¡¡¡ÄÚ´æ·ÖÅ䷽ʽÓÐÈýÖÖ£º
¡¡¡¡[1]´Ó¾²Ì¬´æ´¢ÇøÓò·ÖÅä¡£ÄÚ´æÔÚ³ÌÐò±àÒëµÄʱºò¾ÍÒѾ·ÖÅäºÃ£¬Õâ¿éÄÚ´æÔÚ³ÌÐòµÄÕû¸öÔËÐÐÆڼ䶼´æÔÚ¡£ÀýÈçÈ«¾Ö±äÁ¿£¬static±äÁ¿¡£
¡¡¡¡[2]ÔÚÕ»ÉÏ´´½¨¡£ÔÚÖ´Ðк¯Êýʱ£¬º¯ÊýÄÚ¾Ö²¿±äÁ¿µÄ´æ´¢µ¥Ôª¶¼¿ÉÒÔÔÚÕ»ÉÏ´´½¨£¬º¯ÊýÖ´ÐнáÊøʱÕâЩ´æ´¢µ¥Ôª×Ô¶¯±»ÊÍ·Å¡£Õ»ÄÚ´æ·ÖÅäÔËËãÄÚÖÃÓÚ ......
2.2 ½â¾ö¿É²âÐÔÎÊÌâ
ÉÏÒ»½Ú¾ßÌå·ÖÎöÁ˿ɲâÐÔÎÊÌ⣬½ÓÏÂÀ´£¬ÎÒÃÇÀ´¿´¿´ÈçºÎ½â¾öÕâЩÎÊÌâ¡£ÏÂͼÖУ¬²ÊÉ«µÄ²¿·ÖÊÇÐèÒª½â¾öµÄ¿É²âÐԵľßÌåµÄÎÊÌâ¡£
ÓëÆäËû´úÂë¸ôÀë
ΪÁËÌá¸ßЧÂÊ£¬Ó¦¸ÃÒ»´ÎÐÔ½«Ò»Î»¹¤³Ìʦ¸ºÔðµÄ²âÊÔÈÎÎñ¸ôÀë³öÀ´¡£¸ôÀëʱ£¬Ó¦°ÑÔ´Îļþ·ÖΪÈýÀࣺ± ......
ÔÚCÖпÉÒÔ¶¨ÒåÈ«¾Ö±äÁ¿£¬È«¾Ö±äÁ¿ÊÇÔÚ³ÌÐò¼ÓÔسõʼ»¯Ê±·ÖÅä¿Õ¼ä²¢½øÐгõʼ»¯¡£ÔÚc´úÂëÖж¨Òå/ÉùÃ÷È«¾Ö±äÁ¿µÄ·½Ê½ÈçÏÂ
1. int n;
¶¨Òå»òÕßÉùÃ÷£¨Èç¹ûÔÚÆäËûÎļþÖÐÒѶ¨Ò壩ȫ¾Ö±äÁ¿¡£
2. int n = 10;
¶¨ÒåÈ«¾Ö±äÁ¿²¢³õʼ»¯¡£
3. extern int n;
ÉùÃ÷ÔÚÍⲿ¶¨Ò ......
1 ÒýÑÔ
¡¡¡¡Linux²Ù×÷ϵͳÒò¾ßÓÐÔ´´úÂ빫¿ª¡¢±ãÓڲüõ¡¢Óй㷺µÄ´¦ÀíÆ÷Ö§³ÖµÈÓŵ㣬³ÉΪµ±Ç°Ç¶ÈëʽϵͳµÄÈÈÃÅÑ¡Ôñ¡£»ùÓÚI2C×ÜÏߵļüÅÌÀ©Õ¹É豸Ö÷ÒªÓÃÓÚÂú×ãǶÈëʽÉ豸ÖжԶఴ¼üµÄÐèÇó£¬Çý¶¯³ÌÐòÔÚϵͳÆô¶¯Ê±¶ÔÓ²¼þ½øÐгõʼ»¯¡£ÔÚϵͳÆô¶¯ºóʵÏÖÓ²¼þºÍÓ¦ÓóÌÐòÖ®¼äµÄÊý¾Ý½»»¥¡£Õë¶ÔS3C2410΢´¦ÀíÆ÷ºÍ¼üÅÌɨÃè¹ÜÀíÆ÷¼þ£¬ÉîÈ ......