(ת)³¹µ×¸ã¶¨CÖ¸Õ룺¯ÊýÃûÓ뺯ÊýÖ¸Õë
£¨×ª×Ô£©http://blog.pfan.cn/whyhappy/6030.html
º¯ÊýÃûÓ뺯ÊýÖ¸Õë
Ò» ͨ³£µÄº¯Êýµ÷ÓÃ
Ò»¸öͨ³£µÄº¯Êýµ÷ÓõÄÀý×Ó£º
//×ÔÐаüº¬Í·Îļþ
void MyFun(int x); //´Ë´¦µÄÉêÃ÷Ò²¿Éд³É£ºvoid MyFun( int );
int main(int argc, char* argv[])
{
MyFun(10); //ÕâÀïÊǵ÷ÓÃMyFun(10);º¯Êý
return 0;
}
void MyFun(int x) //ÕâÀﶨÒåÒ»¸öMyFunº¯Êý
{
printf(“%d\n”,x);
}
Õâ¸öMyFunº¯ÊýÊÇÒ»¸öÎÞ·µ»ØÖµµÄº¯Êý£¬Ëü²¢²»Íê³ÉʲôÊÂÇé¡£ÕâÖÖµ÷Óú¯ÊýµÄ¸ñʽÄãÓ¦¸ÃÊǺÜÊìϤµÄ°É£¡¿´Ö÷º¯ÊýÖе÷ÓÃMyFunº¯ÊýµÄÊéд¸ñʽ£º
MyFun(10);
ÎÒÃÇÒ»¿ªÊ¼Ö»ÊÇ´Ó¹¦ÄÜÉÏ»òÕß˵´ÓÊýѧÒâÒåÉÏÀí½âMyFunÕâ¸öº¯Êý£¬ÖªµÀMyFunº¯ÊýÃû´ú±íµÄÊÇÒ»¸ö¹¦ÄÜ£¨»òÊÇ˵һ¶Î´úÂ룩¡£
Ö±µ½——
ѧϰµ½º¯ÊýÖ¸Õë¸ÅÄîʱ¡£ÎҲŲ»µÃ²»ÔÚ˼¿¼£ºº¯ÊýÃûµ½µ×ÓÖÊÇʲô¶«Î÷ÄØ£¿
£¨²»ÒªÒÔΪÕâÊÇûÓÐʲôÒâÒåµÄÊÂàÞ£¡ºÇºÇ£¬¼ÌÐøÍùÏ¿´Äã¾ÍÖªµÀÁË¡££©
¶þ º¯ÊýÖ¸Õë±äÁ¿µÄÉêÃ÷
¾ÍÏóijһÊý¾Ý±äÁ¿µÄÄÚ´æµØÖ·¿ÉÒÔ´æ´¢ÔÚÏàÓ¦µÄÖ¸Õë±äÁ¿ÖÐÒ»Ñù£¬º¯ÊýµÄÊ×µØÖ·Ò²ÒÔ´æ´¢ÔÚij¸öº¯ÊýÖ¸Õë±äÁ¿ÀïµÄ¡£ÕâÑù£¬ÎҾͿÉÒÔͨ¹ýÕâ¸öº¯ÊýÖ¸Õë±äÁ¿À´µ÷ÓÃËùÖ¸ÏòµÄº¯ÊýÁË¡£
ÔÚCϵÁÐÓïÑÔÖУ¬ÈκÎÒ»¸ö±äÁ¿£¬×ÜÊÇÒªÏÈÉêÃ÷£¬Ö®ºó²ÅÄÜʹÓõġ£ÄÇô£¬º¯ÊýÖ¸Õë±äÁ¿Ò²Ó¦¸ÃÒªÏÈÉêÃ÷°É£¿ÄÇÓÖÊÇÈçºÎÀ´ÉêÃ÷ÄØ£¿ÒÔÉÏÃæµÄÀý×ÓΪÀý£¬ÎÒÀ´ÉêÃ÷Ò»¸ö¿ÉÒÔÖ¸ÏòMyFunº¯ÊýµÄº¯ÊýÖ¸Õë±äÁ¿FunP¡£ÏÂÃæ¾ÍÊÇÉêÃ÷FunP±äÁ¿µÄ·½·¨£º
void (*FunP)(int) ; //Ò²¿Éд³Évoid (*FunP)(int x);
Äã¿´£¬Õû¸öº¯ÊýÖ¸Õë±äÁ¿µÄÉêÃ÷¸ñʽÈçͬº¯ÊýMyFunµÄÉêÃ÷´¦Ò»Ñù£¬Ö»²»¹ý——ÎÒÃÇ°ÑMyFun¸Ä³É£¨*FunP£©¶øÒÑ£¬ÕâÑù¾ÍÓÐÁËÒ»¸öÄÜÖ¸ÏòMyFunº¯ÊýµÄÖ¸ÕëFunPÁË¡££¨µ±È»£¬Õâ¸öFunPÖ¸Õë±äÁ¿Ò²¿ÉÒÔÖ¸ÏòËùÓÐÆäËü¾ßÓÐÏàͬ²ÎÊý¼°·µ»ØÖµµÄº¯ÊýÁË¡££©
Èý ͨ¹ýº¯ÊýÖ¸Õë±äÁ¿µ÷Óú¯Êý
ÓÐÁËFunPÖ¸Õë±äÁ¿ºó£¬ÎÒÃǾͿÉÒÔ¶ÔËü¸³ÖµÖ¸ÏòMyFun£¬È»ºóͨ¹ýFunPÀ´µ÷ÓÃMyFunº¯ÊýÁË¡£¿´ÎÒÈçºÎͨ¹ýFunPÖ¸Õë±äÁ¿À´µ÷ÓÃMyFunº¯ÊýµÄ£
Ïà¹ØÎĵµ£º
Ô´Âë:
# include <stdio.h>
int main()
{
/* ¶¨ÒåÁËÒ»¸öÎÞ·ûºÅ×Ö·ûÐͱäÁ¿£¬´Ë±äÁ¿Ö»ÄÜÓÃÀ´´æ´¢ÎÞ·ûºÅÊý */
unsigned char result;
int a, b, c, d;
a = 2;
b = 4; ......
Ô´Âë:
# include <stdio.h>
int main()
{
/* sex´ú±íÊäѪÕßµÄÐÔ±ð£¬weight´ú±íÊäѪÕßµÄÌåÖØ£¬cubage´ú±íÊäѪÁ¿ */
int sex, weight, cubage;
printf("Çë¸ø³öÊäѪÕßµÄÐÔ±ð£¨Å®ÐÔΪ¸ºÊý£©ºÍÌåÖØ£º(ÓöººÅ¸ô¿ª)");
&nbs ......
Ô´Â룺
# include <stdio.h>
int main( )
{
int radius;
double area;
for(radius = 1; radius <= 10 ; radius++)
{
area = 3.1416 * radius * radius;
......
Ô´Â룺
# include <stdio.h>
int main()
{
/* Óгߴç */
/* һάÕûÐÎÊý×é³õʼ»¯ */
int array1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
/* һά×Ö·ûÐÍÊý×é³õʼ»¯£¬×îºóÒ»¸öÔªËØ×Ô¶¯Ìí¼ÓΪ‘/0 ......
ÒÔΪÒѾÕÆÎÕÌõ¼þ±àÒ룬Ԥ±àÒëµÄÒªÁìÁË£¬½á¹û»¹ÊÇ´æÔںܶàÒÅ©µÄµØ·½£¬ËùÒÔ¹æÕûһϣº
Ìõ¼þ±àÒ룺
1
#ifdef _XXXX
...³ÌÐò¶Î1...
#else
...³ÌÐò¶Î2...
#endif
Õâ±íÃ÷Èç¹û±êʶ·û_XXXXÒѱ»#defineÃüÁÒå¹ýÔò¶Ô³ÌÐò¶Î1½øÐбàÒ룻·ñÔò¶Ô³ÌÐò¶Î2½øÐбàÒë¡£
2
#ifndef _XXXX
...³ÌÐò¶Î1...
#else
...³ÌÐ ......