隨手寫了幾行代碼2

 

#include "stdafx.h" #include <iostream> 
using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout << endl << "關於數組的問題" <<endl; int a[] = {1, 2, 3, 4, 5}; int* ptr = (int*)(&a + 1); cout << "*(a + 1) = "<< *(a + 1)<<endl; cout << "*(ptr - 1) = " << *(ptr - 1)<< endl; cout << endl << endl; cout << endl << endl << "關於浮點數 四捨五入 並 保留兩位小數的問題" << endl; float n = 1.235567F; int m = 0; m = n * 100 + 0.5F; n = m / 100.0F; cout << "n = " << n <<endl; cout << "1234532532 / 100.0F = "<< 12345 / 100.0F << endl; cout << endl << endl << "關於strcpy參數長度的問題" << endl; char dest[100], src[10]; for (int i = 0; i < sizeof(src) / sizeof(src[0]); ++ i) { src[i] = 'a'; } src[(sizeof(src) / sizeof(src[0])) - 1] = '\0'; cout << endl <<"源字符串保修以 \\0 結尾" <<endl; strcpy(dest, src); cout << "dest = " << dest << endl; return 0; }

 

 

 

 

執行結果ios

相關文章
相關標籤/搜索