pointer
|
分享:
▲
▼
#include<iostream.h> void main() { int a=1,sum=1; int i,j,array[100]; // 宣个 i , j都为int 型态变数 , array配置 100个int型态大小的元素 int c,d,you[10][10]; //c,d 皆为int型态 ,you[10][10]二维阵列 元素都是int相当一维you[100] char e; long* pointer1 = NULL; //将pointer1初始化先指向NULL就是没有指向任何有效记忆体位址 long data1 = 10,data2 = 20; char A[4][30] = { "天","下","为","公"}; //二维阵列char[4][30] 4 代表有字串个数 30代表长度 char* B[] = { "天","下","为","公"}; //指标阵列 元素是char *型态 可以指向静态记忆体位址字串之类的 pointer1 = &data1; //pointer1指向data1 *pointer1 += 30; //*pointer1相当于指向data1记忆体中取值从data1 + 30 cout << "A=" << data1; pointer1 = &data2; //pointer1改指向data2 data1 = *pointer1*2; //现在*pointer1指向 data2 所以是取址 *2 = 20*2 ; 最后data1 = 40; cout << endl <<"B="<< dec <<data1; cout << endl <<"C="<< dec <<*pointer1; cout << endl <<"E="<< B[2]<< endl; while(a<5) { sum =sum * a; a++; } cout<<"The sum is : "<<sum<<"\n"; for(i=10;i<12;i++){ j=i-1; array[j]=i; cout<<"array["<<j<<"]="<<array[j]<<"\n"; } for(c=0;c<2;c++){ for(d=0;d<1;d++){ you[c][d]=c*10+d+1; cout<<"you["<<c<<"]["<<d<<"]="<<you[c][d]<<"\n"; } } e='d' if(e == 'a') {cout <<"立志贵坚,坚而有恒,其学必成。"<< endl;} else if(e == 'b') {cout <<"等待是偷懒的藉口,怠惰是推托。"<< endl;} else if(e == 'c') {cout <<"君子以同道为友,小人以同利为友。"<< endl; } else if(e == 'd') {cout <<"成功的唯一秘诀-坚持最后一分钟。"<< endl; } }
我只将 * and & 做一些注解其他都是基本的东西所以我没在注解 这题目算是很基本题目 , 如果想学好程式应该自己练习看看
|