一个简单的C++程序

C++ evolved form the programming language C, at the same time, C++ has incorporated many features that were not part of C, such as:
1)symbolic constants,
2)in-line functio substitution,
3)reference types,
4)parametric polymorphism through templates,
5)exceptions.


As a result, C++ has grown to be a complex programming language.


A simple C++ program

#include <cstdlib>
#include <iostream>
int main()
{
	int x, y;
	std::cout << "Please enter two numbers: ";
	std::cin >> x >> y;
	int sum = x + y;
	std::cout << "Their sum is: " << sum << std::endl;	
	return EXIT_SUCCESS;
}

Lines 1 and Line 2 input the two header files, "cstdlib" and "iostream",Header files are used to provide special declarations and definitions, which are of use to the program.
"cstdlib":provides some standard system definitions
"iostream": provides definitions needed for input and output.


The initial entry point for C++ programs is the function main.
The statement "int main()" on line 4 declares main to be a function that takes no arguments and returns
an integer result.


The function body is given within curly braces({...}), which start on line 4 and end on line 11.


The program terminates when the return statement on line 10 is executed.


By convention, the function main returns the value zero to indicate success and returns a nonzero value
to indicate failure. The include file cstdlib defines the constant EXIT_SUCCESS to be 0.Thus, the return statement
on line 10 returns 0, indicating a sucessful termination.


come from the book 《Data structures and algorithms in C++》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值