zoukankan      html  css  js  c++  java
  • 随手写了几行代码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] = '';
    
        cout << endl <<"源字符串保修以 \0 结尾" <<endl;
        strcpy(dest, src);
        cout << "dest = " << dest << endl;
    
     
    
    
        return 0;
    }

    执行结果

  • 相关阅读:
    python os模块
    python time、datetime模块
    python 导入模块、包
    python json、pickle
    python 装饰器
    python 生成器、迭代器
    python 内置函数
    python 函数的参数
    python 编码解码
    python 文件读写、shutil模块
  • 原文地址:https://www.cnblogs.com/cuish/p/3859529.html
Copyright © 2011-2022 走看看