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 & 做一些註解其他都是基本的東西所以我沒在註解 這題目算是很基本題目 , 如果想學好程式應該自己練習看看
|