码迷,mamicode.com
首页 > 其他好文 > 详细

随手写了几行代码2

时间:2014-07-22 22:47:55      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   

 

#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;
}

 

 

 

 

执行结果

bubuko.com,布布扣

随手写了几行代码2,布布扣,bubuko.com

随手写了几行代码2

标签:des   style   blog   http   color   os   

原文地址:http://www.cnblogs.com/cuish/p/3859529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!