First Program in CPP
When learning C++, the first program you write is generally a turning point because it summarizes input, processing, and output. The goal of this pilot program is straightforward: ask the user for a number, then repeat it back. Let us break down this classic C++ program, examining its various parts and features.
Program:
#include<iostream.h>
using namespace std;
int main() {
int a;
cout<<"enter a number"; //input statement
cin>>a;
cout<<"the number is : "<<a; //output statement
return 0;
}
Our program is accompanied with comments, the voiceless guides explaining its inner workings. Single-line comments are indicated with // and give brief annotations; multi-line comments are enclosed in /* */ and offer more context and clarification.
Single Line Comment (// Double Slash)
// This is an example program to add two numbers
// C++ program to illustrate the addition of numbers
Multi-line Comment (/* */)
/*This is an example
program to
add two numbers */
Output Statement (cout)
The cout is a predefined object that represents the standard output stream
Example:
cout<< “C++ is better than c”;
Causes the string in quotation marks to be displayed on the screen.
Input Statement (cin)
The cin is a predefined object that represents the standard input stream
The operator >> is called the extraction or get from operator.
Example
cin>>a;
The value given through the keyboard will be stored in the variable ‘a’.
0 Comments