1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
|
#include <stdio.h> #include<string.h> #include <stdlib.h> #include "add.cpp"
int mySwitch(int a) { switch(a){ case 1: printf("Monday\n"); break; case 2: printf("Tuesday\n"); break; case 3: printf("Wednesday\n"); break; case 4: printf("Thursday\n"); break; case 5: printf("Friday\n"); break; case 6: printf("Saturday\n"); break; case 7: printf("Sunday\n"); break; case 8: printf("8\n"); break; case 9: printf("9\n"); break; case 10: printf("10\n"); break; default:printf("error\n"); break; } return 0; }
int myGoto(int a) { int b = 1; A : b++; printf("b =%u\n",b); if(b<a) { goto A; } printf("goto循环结束 =%u\n",b); return b; }
int myWhile(int a) { int b = 1; while(b<a) { printf("while循环中 b =%u\n",b); b++; if(a==2) { continue; printf("a=2 被continue跳过了,不会打印",b); } } printf("while循环结束 =%u\n",b); return b; }
int myDoWhile(int a){ int b = 1; do { printf("do while循环开始 =%u\n",b); b++; } while (b<=a); printf("do while循环结束 =%u\n",b); return b; }
int myFor(int a) { int b = 1; int c; int d; for(c = 0,d =2;b<a;b++,c++,d++) { printf("for循环 =%u\n",b); } printf("for循环结束 =%u\n",b); return b; } void arrayOverStackTest() { for(;;) { printf("arrayOverStackTest"); } }
int myArrayOverStack(int array[]) { array[6]=(int)&arrayOverStackTest; return 0; }
int methodAgrTest(int a) { return a+1; }
int methodArrAgrTest(int a[]) { return a; }
void arrayTest(int a[],int size) { for(int i =0; i<size;i++) { printf("数组传参传的是数组第一个元素的地址,遍历元素值= %p\n",&a[i]); printf("数组传参传的是数组第一个元素的地址,遍历元素值= %p\n",*(&a[i]));
} }
void arrayPointTest(int* a,int size) { for(int i =0; i<size;i++) { printf("数组指针传参传的是数组第一个元素的地址,遍历元素值= %d\n",*(a+i)); } }
int __cdecl my_cdecl(int a,int b) { return a+b; };
int __stdcall my_stdcall(int a,int b) { return a+b; };
int __fastcall my_fastcall(int a,int b) { return a+b; };
struct myStruct { char c; short s; int i; };
struct my8byteStruct { char c; short s; double i; };
struct myPoint { char a; };
struct myPointSize {
double b; double b1; double b2; };
#pragma pack(2) struct myPragmaStruct { char c; int i; double d; }; #pragma pack()
#pragma pack(2) struct person { char age; char name[0x14]; }; #pragma pack()
#define name1 "021" #define true 1 #define false 0 #define hello1 "你好," #define mystr strcpy(hello1,name1)
int main(int argc, const char * argv[]) { char c = 'a'; short s = 0xffff; int i = 0xffffffff; long l = 0xffffffff; printf("char : %c %d\n",c,c); printf("short : %c %d\n",s,s); printf("int i 无符号: %u int i 有符号: %d\n",i,i);
signed char sc = -1; unsigned char usc = -1; unsigned char usc1 = -2; printf("sc有符号=%d,转换成无符号=%u\n",sc,(unsigned char)sc); printf("sc 无符号数(扩展错误数值) : %u\n",sc); printf("无符号usc=%u,无符号转有符号usc=%d\n",usc,(char)usc);
int i1 = sc; printf("有符号sc数据扩展int=%u,无符号转有符号=%d\n",i1,(int)i1);
char sc1 = 256; printf("数据宽度溢出sc1=%u\n",sc1); char sc2 = -258; printf("数据宽度溢出sc2=%d\n",sc2);
float f = 123.25f; double d = 22.22; printf("浮点数f=%f\n",f); printf("有符号sc数据扩展int=%u",0xffffffac);
mySwitch(6); myGoto(3); myWhile(3); myDoWhile(5); myFor(5); int array[5]; int array1[5] = {1,2,3,4,5}; char charArray[10] ; short shortArray[10] ; myArrayOverStack(array1);
int array2[2][5] = { { 1,2,3,4,5 }, { 5,4,3,2,1 } }; struct myStruct ms = {1,2,3}; printf("结构体属性值 c=%u\n",ms.c);
printf("结构体属性c数据宽度=%u\n",sizeof(ms.c)); printf("结构体属性s数据宽度=%u\n",sizeof(ms.s)); printf("结构体数据宽度=%u\n",sizeof(ms));
struct my8byteStruct m8s = {1,2,3}; printf("结构体m8s属性c数据宽度=%u\n",sizeof(m8s.c)); printf("结构体m8s属性s数据宽度=%u\n",sizeof(m8s.s)); printf("结构体m8s数据宽度=%u\n",sizeof(m8s));
struct myPragmaStruct mps = {1,2,3}; printf("结构体mps属性c数据宽度=%u\n",sizeof(mps.c)); printf("结构体mps属性i数据宽度=%u\n",sizeof(mps.c)); printf("结构体mps属性s数据宽度=%u\n",sizeof(mps.d)); printf("结构体mps数据宽度=%u\n",sizeof(mps)); struct person p[2]; p[0].age = 0x12; stpcpy(p[0].name,"021"); printf("结构体person属性c数据值= %d\n",p[0].age); printf("结构体person属性name数据值= %s\n",p[0].name);
char* cp ; int* ip ; short* sp ; cp = (char*)100; ip = (int*)100; sp = (short*)100; struct person* p1; printf("指针类型person数据值= %p\n",p1); printf("指针类型cp数据值= %d\n",cp); cp++; ip++; sp++; printf("char指针类型cp自增后数据值= %d, 数据宽度=%d\n",cp,sizeof(cp)); printf("int指针类型ip自增后数据值= %d\, 数据宽度=%d\n",ip,sizeof(ip)); printf("short指针类型sp自增后数据值= %d\, 数据宽度=%d\n",sp,sizeof(sp)); if(ip>cp) { printf("指针类型比较后数据值= %d\n",ip); }
printf("取地址符 '&' ,sp地址值= %p\n",&sp); int ip1 = &cp; printf("取地址符 '&' ,ip1地址值= %p cp=%p\n",&ip1,&cp); char* cp1 = &cp; printf("取地址符 '&' ,cp1地址值= %p cp=%p\n",&cp1,&cp);
int* ip2 = &ip; printf("指针取值运算符 '*' ,指针cp1存储的数据值= %d\n",*cp1); printf("指针取值运算符 '*' ,指针ip2存储的数据值= %d\n",*ip2); int i2 = 1; int* ip3 = &i2; printf("指针地址取值'&' 地址值=%p ,指针取值运算符 '*' ,指针cp1存储的数据值= %d\n",&i2,*ip3);
int methodAgr = 1; int methodAgrTestValue = methodAgrTest(methodAgr); methodAgrTest(methodAgr); printf("值传参还是地址传参 答案是值传递数据值= %d\n",methodAgr); printf("值传参还是地址传参 答案是值传递数据值= %d\n",methodAgrTestValue);
int arrayTestArg[2] = {1,2}; arrayTest(arrayTestArg,2); arrayPointTest(&arrayTestArg[0],2);
char str[3] ={'0','2','1',0}; printf("字符串str= %s\n",str); char str1[4] = "021"; printf("字符串str1= %s\n",str1); printf("字符串str1= %s\n",*(&str1)); char str2[9] = "021中国"; printf("strlen函数字符串str1长度= %d,值=%s\n",strlen(str2),&str2); char cp3[6] ; strcpy(cp3, "china"); printf("strcpy复制字符串cp3= %s\n",cp3); char love[10] ; char you[10] ; strcpy(love, "l love"); strcpy(you, "you"); strcat(love,you); printf("strcat拼接字符串= %s\n",love); char love1[9]; char love2[9]; strcpy(love1, "l love"); strcpy(love2, "l love"); int stat =strcmp(love1,love2); if(!stat) { printf("strcmp判断字符串love1与love2相同\n"); }
int ip4 = 1; int* ip5 = &ip4; int** ip6 = &ip5; int*** ip7 = &ip6; int ip8 = *(*(*(ip7))); printf("多级指针 ip8=%d\n",ip8); printf("多级指针 ip7=%d\n",***ip7);
struct myPoint mp; struct myPoint* mp1 = ∓ printf("结构体指针数据宽度 mp1=%lu\n",sizeof(mp1)); mp1->a = 21; printf("结构体指针获取数据值mp1.a=%d\n",mp1->a); int arr[3] ={1,2,3}; struct myPoint* mp2 = (struct myPoint*)&arr; printf("结构体指针获取数据值mp2.a=%d\n",mp2->a);
char arr2[10]; char* arr3[10]; struct myPoint* arr4[10]; char* c2 = "china"; char* c1 = "hello"; char* c3[10] = {c1,c2}; printf("结构体指针获取数据值c3=%s\n",c3[0]); int arr5[3] = {0,1,2}; int* arrPoint = &arr5; int* arrPoint1 = ++arrPoint; printf("结构体指针获取数据值arrPoint=%p ,指针值=%d \n",&arrPoint1,*arrPoint);
int* arrPoint2 = ++arrPoint; printf("结构体指针获取数据值arrPoint=%p ,指针值=%d \n",&arrPoint2,*arrPoint);
int result1 = my_cdecl(2,2); printf("函数指针调用被调用函数返回结果值=%d 返回值地址=%p\n",result1,&result1); int (__cdecl *my_cdeclCall)(int,int);
int arg = 0; int arg1 = 1; my_cdecl(0,1); my_stdcall(0,1); my_fastcall(0,1);
printf("自定义宏调用返回结果值=%s \n",name1);
int fileResult = myAdd(1,2); printf("使用包含文件函数,返回结果=%d \n",fileResult); return 0; }
|