程序清单2.5_stillbad.c_程序_《C Primer Plus》P27

// stillbad.cpp : 定义控制台应用程序的入口点。
//
/* stillbad.c -- 修正了语法错误的程序 */
/*
    时间:2018年05月31日 21:51:51
    代码:程序清单2.5_stillbad.c_程序_《C Primer Plus》P27
    目的:了解语义的错误(程序运行结果并非作者的意图时,请动笔画图示意)
*/
#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    int n, n2, n3;
    /* 该程序有语义错误 */

    n = 5;
    n2 = n * n;        //
    n3 = n2 * n;    // 原来是 n3 = n2 * n2; 如此结果就成了四次方了;
    /* squared(求平方); cubed(求立方) */
    printf("n = %d, n squared = %d, n cubed = %d\n", n, n2, n3);
    getchar();

    return 0;
}

/*
    在VS2010中运行结果:
--------------------------------------
n = 5, n squared = 25, n cubed = 125
--------------------------------------
*/


猜你喜欢

转载自blog.51cto.com/13555061/2122623
今日推荐