1.1 »ù±¾Êý¾ÝÀàÐÍ
1.1.1 Êý¾ÝÀàÐ͵Ä˵Ã÷
ʵÏÖ¹¦ÄÜ-------Êý¾Ý´¦Àí---------´æ´¢ÄÚ´æ----->Õ¼ÓÃÄÚ´æ¿Õ¼ä´óС----->Êý¾ÝÀàÐÍ
ºâÁ¿ÄÚ´æ¿Õ¼ä´óСµÄµ¥Î»---------->×Ö½ÚByte λ bit£¨±à³Ì£©
1. Êý¾ÝÀàÐ͵Ä×÷ÓÃ
1£©Êý¾ÝÀàÐ;ö¶¨¶ÔÓ¦µÄÊý¾ÝËùÕ¼µÄÄÚ´æ¿Õ¼ä´óС
2£©Êý¾ÝÀàÐ;ö¶¨Êý¾ÝÔÚÄÚ´æÖеÄÅÅÁз½Ê½£¨Î»ÅÅÁз½Ê½---->´æ´¢¸ñʽ£©
3£©Êý¾ÝÀàÐ;ö¶¨ÄÚ´æ¿Õ¼ä´æ´¢µÄÊý¾ÝµÄ·¶Î§
4£©Êý¾ÝÀàÐ;ö¶¨Êý¾ÝµÄʹÓ÷½Ê½
2. Êý¾ÝÀàÐ͵ķÖÀࣺ(Á˽â)
1£©»ù±¾Êý¾ÝÀàÐÍ£º ÕûÐÍ ×Ö·ûÐÍ ÊµÐÍ£¬ ¹Ì¶¨£¬²»¿É²ð·Ö£¬
2£©¹¹ÔìÊý¾ÝÀàÐÍ£ºÓÉÆäËûÀàÐ͹¹Ôì³öÀ´ÀàÐÍ£¬¿É²ð·ÖΪ»ù±¾Êý¾ÝÀàÐÍ
Êý×éÀàÐÍ
½á¹¹ÌåÀàÐÍ
¹²ÓÃÌåÀàÐÍ
ö¾ÙÀàÐÍ
3£©Ö¸ÕëÀàÐÍ
1£©¿ÕÀàÐÍ£º void ÓÃÓÚº¯ÊýµÄ²ÎÊý£¬º¯ÊýµÄ·µ»ØÖµ
void * ÍòÄÜÐÍÖ¸Õë
1.1.2 ÕûÐÍ
1. ´¿Êý×Ö×é³É£¬ÕûÊý£¬ÓÃÕûÐͱíʾ£¬ 89 9000 467 -199 -399 145235 56 45 7788
2. ³£Óùؼü×Ö£º int ËùÕ¼ÄÚ´æ¿Õ¼ä´óС4¸ö×Ö½Ú
3. ·ÖÀࣺ
1£©¶ÌÕûÐÍ£º short (int) ËùÕ¼¿Õ¼ä´óС2¸ö×Ö½Ú £¬ intÊ¡ÂÔ²»Ð´
2£©ÕûÐÍ int ËùÕ¼¿Õ¼ä´óС4¸ö×Ö½Ú£¬
²»Í¬±àÒëƽ̨£¬ËùÕ¼¿Õ¼ä´óС²»Ò»Ñù, win32ƽ̨Ï£¬¿Õ¼ä´óСһ°ã¶¼ÊÇ4¸ö×Ö½Ú
3£©³¤ÕûÐÍ long (int) ËùÕ¼¿Õ¼ä´óС4¸ö×Ö½Ú intÊ¡ÂÔ²»Ð´
4£©³¤³¤ÕûÐÍ£º long long (int) ¿Õ¼ä´óС8¸ö×Ö½Ú
1£© ÓзûºÅÊý¾Ý£º Êý¾ÝÓÐÕý¸ºÖ®·Ö£¬¹Ø¼ü×Ö£ºsigned, Ò»°ãÊ¡ÂÔ²»Ð´£¬Ä¬ÈÏΪÓзûºÅÊý¾Ý
´æ´¢¸ñʽ£º ·ûºÅλ+Êý¾Ýλ
·ûºÅλ£ºÀûÓÃ×î¸ßλ±íʾ·ûºÅ룬×î¸ßλ1£¬¸ºÊý£¬×î¸ßλΪ0£¬ÕýÊý
2£©ÎÞ·ûºÅÊý¾Ý£º Êý¾ÝûÓÐÕý¸ºÖ®·Ö£¬Ï൱ÓÚÖ»ÓÐÕýÊý£¬Ã»ÓиºÊý£¬¹Ø¼ü×Ö£º unsigned
´æ´¢¸ñʽ£ºÊý¾Ýλ
int main() { //ÓзûºÅÊý¾Ý£¬signed Ê¡ÂÔ²»Ð´ int age; //signed int age ; long long b = 689; //signed long long b = 689; int g = -1111; printf("%d\n",g); //ÎÞ·ûºÅÊý¾Ý unsigned int c = 100; unsigned short f = 90; //unsigned short int f = 90 return 0; } |
1. ´æ´¢Êý¾ÝµÄ·¶Î§
ÒÔint£¬ unsigned int ΪÀý
1£©ÓзûºÅÕûÐÍ£º
×î´óÖµ£º·ûºÅλΪ0£¬31Êý¾ÝλΪ1£¬ 2147483647
×îСֵ£º·ûºÅλΪ1, 31Êý¾ÝλΪ0£¬ - 21474836478
2£©ÎÞ·ûºÅÕûÐÍ£º
×î´óÖµ£º32¸öÊý¾ÝλΪ1£¬4294967295
×îСֵ£º32¸öÊý¾ÝλΪ0£¬ 0
Á·Ï°£º
short [-32768,32767]
unsigned short [0,65535]
2. Êý¾ÝµÄÒç³ö¹æÂÉ
¸ø±äÁ¿¸³Öµ£¬³¬¹ýÊý¾ÝÀàÐͶÔÓ¦µÄ·¶Î§£¬Ôò·¢ÉúÊý¾ÝµÄÒç³ö£¬ÔÚÄÚ´æÖд洢µÄÊý¾ÝÊÇÒç³öºóµÄÊý¾Ý
int a = 2147483649; //2147483649 ²»ÔÚintÀàÐÍÊý¾Ý·¶Î§ÄÚ£¬Ôò·¢ÉúÒç³ö
1£© Êý¾ÝÈç¹û´Ó×î´óÖµ·½ÏòÒç³ö£¬Ôò´Ó×îСֵ¿ªÊ¼µÝÔö
2£© Êý¾ÝÈç¹û´Ó×îСֵ·½ÏòÒç³ö£¬Ôò´Ó×î´óÖµ¿ªÊ¼µÝ¼õ
1.1.3 ×Ö·ûÐÍ
1. ±íʾ£¬Óõ¥ÒýºÅÀ¨ÆðÀ´µÄÊý¾Ý£¬¡®a¡¯¡®+¡¯ ¡®&¡¯ ¡®k¡¯¡®@¡¯¡®\t¡¯¡®\n¡¯ ¡®\101¡¯(°Ë½øÖƱíʾ×Ö·û)
¡®\xab¡¯(Ê®Áù½øÖÆ×Ö·û)
2. Ò»¸ö×Ö·ûʵ¼ÊÉÏÔÚÄÚ´æÖÐÊÇÒÔÕûÐ͵ĸñʽ´æ´¢£¬ÓÃÒ»¸öÌض¨µÄÕûÊý±íʾһ¸öÌض¨µÄ×Ö·û£¬×Ö·ûÓëÕûÊýÖ®¼ä´æÔÚÒ»Ò»¶ÔÓ¦µÄ¹Øϵ£¬ÓÉASCIIÂë±í£¨ÃÀ¹ú±ê×¼ÐÅÏ¢½»»»±í£©¾ö¶¨
3. ·ÖÀࣺ
ÓзûºÅ×Ö·û£º (signed) char £¬ËùÕ¼¿Õ¼ä´óС1¸ö×Ö½Ú,signed Ê¡ÂÔ²»Ð´£¬Ä¬ÈÏÓзûºÅÊý¾Ý
ÎÞ·ûºÅ×Ö·û£º unsigned char , ËùÕ¼¿Õ¼ä´óС1¸ö×Ö½Ú
1. ´æ´¢·¶Î§£º
char [-128,127] //
unsigned char [0,255]
2. ×Ö·ûµÄ·ÖÀà
1£©¿ØÖÆ×Ö·û(תÒå×Ö·û)£ºÖ»ÌåÏÖ¹¦ÄÜ£¬²»ÏÔʾ×Ö·û±¾Éí£¬¡¯\n¡¯
2£©´òÓ¡×Ö·û£º ¿ÉÒÔÏÔʾÔÚÏÔʾÖÕ¶ËÉÏ£¬ÏÔʾ×Ö·û±¾Éí
¡®\0¡¯ -------------- 0 ¿Õ×Ö·û
¡®\n¡¯ ------------ 10 »»ÐÐ
¡®\t¡¯ --------- 9 ˮƽÖƱí·û£¬±íʾһ¸ö·ûÔÚÏÔʾÖÕ¶ËÕ¼8¸ö×Ö·ûµÄλÖÃ
¡®\r¡¯ ----------- 13 »Ø³µ
±ê×¼»»ÐС®\r¡¯¡¯\n¡¯
¡®0¡¯ ~ ¡®9¡¯ 48 ~ 57
¡®A¡¯~ ¡®Z¡¯ 65 ~ 90
¡®a¡¯ ~ ¡®z¡¯ 97 ~ 122
¡® ¡¯ ------ 32 ¿Õ¸ñ×Ö·û
¡®\hhh¡¯ h[0,7],²ÉÓð˽øÖƵÄÐÎʽ±íʾһ¸ö×Ö·û
¡®\101¡¯--------->1*8^2 + 0 *8^1+1*8^0 =65
¡®\xhh¡¯ h[0,F] ²ÉÓÃÊ®Áù½øÖƵÄÐÎʽ±íʾһ¸ö×Ö·û, x ±íʾʮÁù½øÖÆ
¡®\x41¡¯ ------->65
\¡¯ µ¥ÒýºÅ
\¡± Ë«ÒýºÅ
int main() { //×Ö·ûÊý¾Ý char char a = 'K'; //¸ø×Ö·û±äÁ¿¸³×Ö·ûÖµ
printf("%d\n",a); //´òÓ¡×Ö·ûaµÄASCIIÂëÖµ printf("%c\n",a); //ÒÔ×Ö·ûµÄ¸ñʽ´òÓ¡aµÄÖµ
char b = 67; //Ê®½øÖÆ //¸ø×Ö·û±äÁ¿¸³ACIIÂëÖµ printf("%c\n",b);
char ch = 3; //¸ø×Ö·û±äÁ¿¸³ASCIIÂëֵΪ3µÄ×Ö·û printf("%c\n",ch);
char bf = '\n'; bf = '\0'; printf("bf = %c\n",bf); //תÒå×Ö·ûÌåÏÖ¹¦ÄÜ£¬²»ÏÔʾ×Ö·û±¾Éí printf("bf = %d\n",bf);
printf("hell world\n"); printf("\tsjhk\n"); //\t ¹¦ÄÜ£¬Õ¼8¸ö×Ö·ûµÄλÖÃ
char pk = '\101'; //°Ë½øÖÆ printf("%d\n",pk); //ASCIIÂëÖµ printf("%c\n",pk); pk = '\x42'; //Ê®Áù½øÖÆ printf("%d\n",pk); //ASCIIÂëÖµ printf("%c\n",pk); } |
Á·Ï°£º
1£©¶ÔÓÚÒ»¸ö×Ö·ûÊÇ·ñÄܹ»²ÎÓëÔËË㣿
¡®a¡¯*4 +¡¯B¡¯ //¿ÉÒÔ
97*4+66
2£©ÈçºÎ½«Ò»¸öÊý×Ö×Ö·ûchת»»ÎªÕûÐÍÊý¾Ý£¿
¡®5¡¯-------->5
ch ¨C 48;
3£©´óС×Öĸд×Ö·ûch(Сд×Ö·û) Ï໥ת»»£¿
CH + 32 == ch
ch ¨C 32 == CH£¨´óд×Ö·û£©
4£©ÈçºÎÅжÏÒ»¸ö×Ö·ûch£¬ÊÇ·ñΪ´óдµÄ×Öĸ×Ö·û£¿
if(ch >= ¡®A¡¯ && ch <= ¡®Z¡¯) {//´óдµÄ×Ö·û}
5£©Êý¾ÝµÄ¼ÆËã
char ch = 130;
printf(¡°%d\n¡±,ch); //
char ph = ¡®z¡¯;
ph = ph *4;
printf(¡°%d\n¡±,ph)?
{ //char [-128,127] char ch = 130; //130 - 256 printf("%d\n",ch);
ch = 'z' * 4; //122 * 4 = 488 //488 - 256 - 256 printf("%d\n",ch); } |
1.1.4 ʵÐÍ
1.Ò²³ÆΪ¸¡µãÐÍ£¬ÓÉСÊýµã×é³ÉµÄÊý¾Ý 90.23 1.23 4.56 90.0
2. ·ÖÀࣺ µ¥¾«¶È ¹Ø¼ü×Ö float ËùÕ¼µÄÄÚ´æ¿Õ¼ä´óС4¸ö×Ö½Ú
Ë«¾«¶È ¹Ø¼ü×Ödouble ËùÕ¼µÄÄÚ´æ¿Õ¼ä´óС8¸ö×Ö½Ú
3.ʵÐÍÊý¾Ý²»Ê¹ÓÃsigned »òÕßunsigned ÐÞÊÎÊÇ·ñΪÓзûºÅÊý¾Ý
4. ʵÐÍÊý¾ÝÔÚÄÚ´æÖеĴ洢¸ñʽ£º·ûºÅλ + СÊýλ+ Ö¸Êýλ,¸úÕûÐͺÍ×Ö·ûÐ͵Ĵ洢¸ñʽ²»Ò»Ñù
5.·¶Î§
floatºÍdoubleµÄ·¶Î§ÊÇÓÉÖ¸ÊýµÄλÊýÀ´¾ö¶¨µÄ£¬floatµÄÖ¸ÊýλÓÐ8룬¶ødoubleµÄÖ¸ÊýλÓÐ11룬·Ö²¼ÈçÏ£º
float£º 1bit£¨·ûºÅ룩 8bits £¨Ö¸Êý룩 23bits£¨Î²Êý룩 //32bit
double£º 1bit£¨·ûºÅ룩 11bits£¨Ö¸Êý룩 52bits£¨Î²Êý룩 //64bit
ÓÚÊÇ£ºfloatµÄÖ¸Êý·¶Î§Îª -127~+128
doubleµÄÖ¸Êý·¶Î§Îª -1023~+1024
²¢ÇÒÖ¸ÊýλÊÇ°´²¹ÂëµÄÐÎʽÀ´»®·ÖµÄ¡£ÆäÖиºÖ¸Êý¾ö¶¨Á˸¡µãÊýËùÄܱí´ïµÄ¾ø¶ÔÖµ×îСµÄ·ÇÁãÊý£»¶øÕýÖ¸Êý¾ö¶¨Á˸¡µãÊýËùÄܱí´ïµÄ¾ø¶ÔÖµ×î´óµÄÊý£¬Ò²¼´¾ö¶¨Á˸¡µãÊýµÄÈ¡Öµ·¶Î§¡£
floatµÄ·¶Î§Îª -2^128 ~ +2^128£¬ Ò²¼´ -3.40E+38 ~ +3.40E+38£»// 3.4*10^38 doubleµÄ·¶Î§Îª -2^1024 ~ +2^1024£¬Ò²¼´ -1.79E+308 ~ +1.79E+308¡£
6. ˵Ã÷£ºÊý¾Ý±È½ÏµÄʱºò£¬²»Ê¹ÓÃʵÐÍÊý¾Ý
1£©ÕûÐͱäÁ¿ÓëÁãÖµ±È½Ï£¬Ó¦µ±½«ÕûÐͱäÁ¿Óá°==¡±»ò¡°£¡ =¡±Ö±½ÓÓë 0 ±È½Ï¡£
¼ÙÉèÕûÐͱäÁ¿µÄÃû×ÖΪ value£¬ËüÓëÁãÖµ±È½ÏµÄ±ê×¼ if Óï¾äÈçÏ£º
if (value == 0)
if (value != 0)
2£©¸¡µã±äÁ¿ÓëÁãÖµ±È½Ï£¬²»¿É½«¸¡µã±äÁ¿Óá°==¡±»ò¡°!=¡±ÓëÈκÎÊý×ֱȽϡ£Ç§ÍòÒªÁôÒ⣬ÎÞÂÛÊÇ float »¹ÊÇ double ÀàÐ͵ıäÁ¿£¬¶¼ÓÈÏÞÖÆ¡£ËùÒÔÒ»¶¨Òª±ÜÃ⣬½«¸¡µã±äÁ¿Óá°==¡±»ò¡°£¡=¡±ÓëÊý×ֱȽϣ¬Ó¦¸ÃÉ跨ת»¯³É¡°>=¡±»ò¡°<=¡±ÐÎʽ¡£
¼ÙÉ踡µã±äÁ¿µÄÃû×ÖΪ x£¬Ó¦µ±½«
if (x ==0.0) // Òþº¬´íÎóµÄ±È½Ï
ת»¯Îª
if((x>=-EPSINON) && (x<=EPSINON))
ÆäÖÐ EPSINON ÊÇÔÊÐíµÄÎó²î£¨¼´¾«¶È£©
{ int ph = 65; //·ûºÅλ+Êý¾Ýλ
printf("%c\n",ph); printf("%d\n",ph); printf("%f\n",ph); //·ûºÅλ+СÊýλ+Ö¸Êýλ
float pg = 57.67; printf("%f\n",pg); printf("%d\n",pg);
//1) ÊÊÓÃÓÚʵÐÍÊý¾ÝµÄ¸ñʽ·û%f %lf ²»ÄÜÓÃÓÚÕûÐÍÊý¾ÝºÍ×Ö·ûÐÍÊý¾Ý // ÊÊÓÃÓÚ×Ö·ûºÍÕûÐÍÊý¾ÝµÄ¸ñʽ·û ²»ÄÜÓÃÓÚʵÐÍÊý¾Ý
//2) ʵÐÍÊý¾ÝÓÈÏÞÖÆ£¬¸ø±äÁ¿¸³µÄÖµºÍÔÚÄÚ´æÖд洢µÄÖµÓÐÎó²î·¶Î§ // ʵÐÍÊý¾Ý²»ÄÜÓëÈκÎÊý×ÖÖ±½Ó½øÐÐ±È½Ï //float a ; if(a) //Êýѧ£º0-0.01 >= 0 <= 0+0.01 } |