标签:har sizeof 遍历 add dllexport ima define 通过 vs2012
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 int num[3][4]; 6 int i,j; 7 for (i = 0; i < 3; i++) 8 { 9 for (j = 0; j < 4; j++) 10 { 11 num[i][j]=4*i+j+1; 12 printf("%-3d",num[i][j]); 13 } 14 printf("\n"); 15 } 16 system("pause"); 17 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 int a[3][4]; 6 int i; 7 printf("%x\n",a); 8 //一个循环赋值二维数组 9 for (i = 0; i < 12; i++) 10 { 11 a[i/4][i%4]=i;//以第二个下标为准,如a【2】【6】,则a【i/6】【i%6】 12 printf("%-3d",a[i/4][i%4]); 13 } 14 15 system("pause"); 16 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 //赋值为0.二维数组全部为0 6 //int a[3][4] = { 0 }; 7 8 //二维数组可以当作,一个一维数组每一个元素又是一个一维数组 9 //int a[3][4] = { { 1, 2 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }; 10 11 //int a[][4] = { {1,2,3,4} }; 12 //大括号初始化了以后,行数可以省略 13 //列坐标不可以省略, 14 //int a[3][] = { { 0 }, { 0 }, { 0 } }; 错误!!! 15 16 //当声明语句中提供有全部元素的初始值时,第1维的大小可以缺省 17 //N维数组,有大括号初始化有确定的因素,只有第一个可以省略 18 19 //int num[2][3]={{1},{2}}; 等价于 20 int a[2][3]={{1,0,0},{2,0,0}}; 21 22 printf("%d", sizeof(a)); 23 printf("\n%x", &a); 24 25 system("pause"); 26 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; 6 int i,j; 7 for (i = 0; i < 3; i++) 8 { 9 for (j = 0; j < 4; j++) 10 { 11 //a[i]+j==&a[i][j],*(&a[i][j])==*(a[i]+j)==a[i][j] 12 printf("%d,%d,%x,%x ",a[i][j],*(&a[i][j]),&a[i][j],a[i]+j); 13 } 14 printf("\n"); 15 } 16 //a[x]代表第x行第一个元素首地址 ,某一行这个数组的首地址 17 printf("\na[0]=%x,a[1]=%x,a[2]=%x",a[0],a[1],a[2]); 18 19 system("pause"); 20 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 int i,j,n,sum=0; 6 int a[10][10]; 7 printf("请输入一个正整数n(1<n<=10):"); 8 scanf("%d",&n); 9 10 for (i = 0; i < n; i++) 11 { 12 for (j = 0; j < n; j++) 13 { 14 a[i][j]=i*n+j+1; 15 printf("%-3d",a[i][j]); 16 } 17 printf("\n"); 18 } 19 for (i = 0; i < n; i++) 20 { 21 sum+=a[i][i]; 22 } 23 printf("%d\n",sum); 24 system("pause"); 25 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; 6 int i,j,b[4][3]; 7 for (i = 0; i < 3; i++) 8 { 9 for (j = 0; j < 4; j++) 10 { 11 printf("%-3d", a[i][j]); 12 } 13 printf("\n"); 14 } 15 printf("转置\n"); 16 for (i = 0; i < 4; i++) 17 { 18 for (j = 0; j < 3; j++) 19 { 20 b[i][j]=a[j][i]; 21 printf("%-3d",b[i][j]); 22 } 23 printf("\n"); 24 } 25 system("pause"); 26 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 int a[5][4][3]; 6 int i,j,k,num=0; 7 printf("%d\n", sizeof(a)); 8 for (i = 0; i < 5; i++) 9 { 10 for (j = 0; j < 4; j++) 11 { 12 for (k = 0; k < 3; k++) 13 { 14 a[i][j][k] = ++num; 15 printf("%-5d", a[i][j][k]); 16 } 17 printf("\n"); 18 } 19 printf("\n"); 20 } 21 printf("%x", a); 22 getchar(); 23 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 int a[5][4][3]; 6 int i; 7 for (i = 0; i < 3*4*5; i++) 8 { 9 a[i/(4*3)][i/3%4][i%3]=i+1; 10 if(i%3==0) printf("\n"); 11 if(i%(4*3)==0) printf("\n"); 12 printf("%-3d",a[i/(4*3)][i/3%4][i%3]); 13 } 14 getchar(); 15 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 #define N 100 5 int i;//VS2012的麻烦之处 6 7 //数组初始化 8 void operate(int a[]){ 9 for (i = 0; i < N; i++) 10 { 11 a[i]=i+1; 12 printf("%d\t",a[i]); 13 } 14 } 15 16 //进行遍历查找 17 int search(int a[],int num){//数组,所求数字 18 for (i = 0; i < N; i++) 19 { 20 if(a[i]==num) return i; 21 } 22 return -1; 23 } 24 25 //进行二分查找 26 int search2(int a[],int num){ 27 int start=0,end=N-1,middle=(start+end)/2; 28 while (a[start]<=a[end]) 29 { 30 printf("查找:%d,%d,%d\n",a[start],a[end],a[middle]); 31 if(a[middle]==num) return middle; 32 else if(a[middle]>num){ 33 end=middle-1; 34 middle=(start+end)/2; 35 }else 36 { 37 start=middle+1; 38 middle=(start+end)/2; 39 } 40 } 41 return -1; 42 } 43 44 //for循环实现二分查找 45 int search3(int a[],int num){ 46 int start,end,middle; 47 for(start=0,end=N-1,middle=(N-1)/2;a[start]<=a[end];middle=(start+end)/2){ 48 printf("查找:%d,%d,%d\n",a[start],a[end],a[middle]); 49 if(a[middle]==num) return middle; 50 else if(a[middle]>num) end=middle-1; 51 else start=middle+1; 52 } 53 } 54 55 void main(){ 56 int a[N],num,x; 57 operate(a);//数组初始化 58 printf("请输入要查找的数字:"); 59 scanf("%d",&num); 60 x=search3(a,num); 61 if(x==-1) printf("该数组无此数!"); 62 else printf("找到%d\n",a[x]); 63 system("pause"); 64 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<Windows.h> 4 5 void msg(){ 6 while(1){ 7 MessageBoxA(0,"阿飞的目标:108个媳妇","阿飞的爱情游戏",0); 8 Sleep(2000); 9 } 10 } 11 12 void main(){ 13 int num=100; 14 printf("%x,%x\n",&num,msg);//函数的本质是一个内存地址 15 while(1){ 16 Sleep(2000); 17 printf("把妹%d\n",num); 18 } 19 }
dll文件
1 _declspec(dllexport) void go(){ 2 int *p=(int *)0x22fe48; 3 *p=-50;//改值 4 5 void(*p1)()=(void(*)())0x12a111d; 6 p1();//调用函数 7 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int add(int a,int b){ 5 return a+b; 6 } 7 8 void main(){ 9 int num=100; 10 int *p=#//p是一个指针变量,存储的是num地址 11 int(*pp)(int a,int b); 12 *p=19;//通过地址修改变量,*p根据地址取出内容 13 //*(&num)=18;等价于上面一句 14 printf("%d\n",num); 15 16 //printf("%d\n",add(1,5)); 17 pp=add; 18 printf("%d\n",pp(1,2)); 19 20 getchar(); 21 }
[c/c++] programming之路(15)、多维数组和二分查找法,小外挂
标签:har sizeof 遍历 add dllexport ima define 通过 vs2012
原文地址:http://www.cnblogs.com/little-monkey/p/7405644.html