ÎÒµÄCʵ¼ù(1)£ººêµÄÓ¦ÓÃ
1¡¢ÎªÁ˵÷ÓúêʱÄܵõ½ÕýÈ·½á¹û£¬ÔÚºêÌåÖн¨Òé¶ÔºêµÄÿ¸ö²ÎÊýÓÃÀ¨ºÅÀ¨ÆðÀ´£¬²¢ÇÒµ±ºêÌåÊÇÒ»¸ö±í´ïʽʱÕû¸öºêÌåÒ²ÓÃÀ¨ºÅÀ¨ÆðÀ´¡£
/* c1.c£º½«Á½¸öÊýÏà³Ë */
#define product(x,y) ((x)*(y))
#include <stdio.h>
int main(){
int a=1,b=2,c=3,d=4,x=0;
x=product(a+3,b)+product(c,d); /* ÈôºêÌåÖÐûÓÐʹÓÃÀ¨ºÅ£¬ÔòµÃ²»µ½
ÄãÏëÒªµÄ½á¹û */
printf("%d\n",x);
return 0;
}
2¡¢ÓúêÀ´²åÈëÈÎÒâÓï¾ä¡£
/* c2.c£º²åÈëÈÎÒâÓï¾ä */
#define insert(stmt) stmt /* ²åÈëÈÎÒâÓï¾ä */
#include <stdio.h>
int main(){
int a,b;
insert({ a=1;b=1; }) /* ÕâÊÇÒ»¸ö¸´ºÏÓï¾ä */
insert({ a=1,b=1; }) /* Èç¹û¶ººÅ±í´ïʽ²»ÓÃÔ²À¨ºÅÀ¨Æð£¬ÔòÔ¤´¦ÀíÆ÷»áÈÏΪ
ÓÐÁ½¸öʵ²Î£¬±¨´í */
printf("a=%d, b=%d\n",a,b);
return 0;
}
×¢Ò⣬µÚ2¸öµ÷ÓÃÖжººÅ±í´ïʽÓï¾äÒªÓÃÀ¨ºÅÀ¨ÆðÀ´£¬·ñÔòÔ¤´¦ÀíÆ÷»áÈÏΪ¸øºê´«ÁËÁ½¸öʵ²Î£¬ÓÉÓÚûÓÐÁ½¸öʵ²ÎµÄincr£¬Òò´Ë»á±¨´í¡£
3¡¢ÎªÁËʹº¯ÊýʽºêÄÜÏñÕæÕýµÄº¯ÊýÒ»Ñù¹¤×÷£¬½¨ÒéÓÃdo{ }while(0)Óï¾ä°üסºêÌåµÄ´úÂë¡£
/* c3.c£º ½»»»Á½¸öÕûÐͱäÁ¿µÄÖµ */
/* #define swap(x,y) { int temp=x; x=y; y=temp; } */
#define swap(x,y) \
do { int temp=x; x=y; y=temp; } while(0)
#include <stdio.h>
int main(){
int x=4,y=3;
if(x>y) swap(x,y); /* ÓõÚÒ»¸öswapʱ»á³ö´í£¬µ¼ÖÂ{ }ºóÃæÓÐÒ»¸ö·ÖºÅ£¬
Óõڶþ¸öswapÔòûÎÊÌâ */
else x=y;
printf("x=%d, y=%d\n",x,y);
return 0;
}
Èç¹ûÓÃ×¢ÊÍÖж¨ÒåÄǸöswap£¬Ôòif {...};ºóÃæ»áÒ»¸ö·ÖºÅ£¬µ¥¶ÀµÄ·ÖºÅÊÇÒ»¸ö¿ÕÓï¾ä£¬Õâµ¼ÖÂifÓëelseÖ®¼äÓÐÁ½¸öµ¥¶ÀµÄÓï¾ä²»ºÏ·¨¡£¶øÓÃdo{ }while(0)Ì×סÓï¾äʱÔò²»»áÓÐÕâÑùµÄÎÊÌâ¡£
4¡¢ÓúêÀ´°ü×°Óï¾ä¡£
/* c4.c£º´òÓ¡1µ½20µÄÁ¢·½±í£¬ÓúêÀ´°ü×°Ñ»·Óï¾ä */
#define incr(v,low,high) \
for((v)=(low); (v)<=(high); (v)++)
#include <stdio.h>
int main(){
int j;
incr(j,1,20)
printf("%2d %6d\n",j,j*j*j);
return 0;
Ïà¹ØÎĵµ£º
1. ö¾ÙµÄ¶¨Òåö¾ÙÀàÐͶ¨ÒåµÄÒ»°ãÐÎʽΪ£º
enum ö¾ÙÃû{ ö¾ÙÖµ±í };
ÔÚö¾ÙÖµ±íÖÐÓ¦ÂÞÁгöËùÓпÉÓÃÖµ¡£ÕâЩֵҲ³ÆÎªÃ¶¾ÙÔªËØ¡£
ÀýÈ磺
¸Ãö¾ÙÃûΪweekday£¬Ã¶¾ÙÖµ¹²ÓÐ7¸ö£¬¼´Ò»ÖÜÖÐµÄÆßÌì¡£·²±»ËµÃ÷ΪweekdayÀàÐͱäÁ¿µÄȡֵֻÄÜÊÇÆßÌìÖеÄijһÌì¡£
2. ö¾Ù±äÁ¿µ ......
»ñÈ¡IPµÄC ´úÂë #include<stdio.h> #include<winsock2.h> #pragma comment(lib,"ws2_32.lib") void CheckIP(void) //¶¨ÒåCheckIP£¨£©º¯Êý£¬ÓÃÓÚ»ñÈ¡±¾»úIPµØÖ· { WSADATA wsaData; char name[255]; //¶¨ÒåÓà ...
»ñÈ¡IPµÄC ´úÂë
#include<stdio.h>
#include<winsock2.h>
#pragma comment(li ......
×î½üÒ»¶Îʱ¼äÔÚÑо¿ Pro*C Óöµ½Á˺ܶà³õ¼¶ÎÊÌâ¡£ÔÚ Pro*C ÖÐÁ¬½ÓÊý¾Ý¿âʱ£¬ÎÒÃÇÒ»°ãÊÇʹÓÃÔÚ“tnsnames.ora”ÖÐÅäÖúÃÁ¬½Ó£¬Ð´ÆðÀ´ºÜ¼òµ¥£¬Óï·¨ÈçÏ£º
EXEC SQL CONNECT :username IDENTIFIED BY :password USING :dbname;
/* ÕâÀïµÄ dbname ¾ÍÊÇÔÚ ......
Ò»¸öC³ÌÐòµÄÄÚ´æ²¼¾Ö(memory layout)
2009-09-09 15:19
Ò»¸öC³ÌÐòÒ»Ö±ÒÔÀ´¶¼ÊÇÓÉÒÔÏÂ5¸ö¶Î(pieces)×é³É£º
´úÂë¶Î(text segment)£º´æ·ÅCPUÖ´ÐеĻúÆ÷Ö¸Áî(machine instructions)¡£Í¨³£Çé¿öÏ£¬´úÂë¶ÎÊǿɹ²ÏíµÄ£¬Ê¹Æä¿É¹²ÏíµÄÄ¿µÄÊǶÔÓÚÆµ·±±»Ö´ÐеijÌÐò£¬Ö»ÐèÒªÔÚÄÚ´æÖÐÓÐÒ»·Ý¿½±´¼´¿É£¬±ÈÈçÎı¾±à¼Æ÷(text editors)£¬C ......