Tuesday, June 30, 2020

CHAPTER-1(PART-2)

C++ Hello World program with explanation

We shall learn about C++ program structure.
Open any c++ editor(i am using Dev-C++),create a new file and name it accordingly.here the name is Untitled.cpp



  1. #include<iostream>
Here #include is a pre-processor directive.
iostream is a header file name.in C++ we don't need to include ".h"extension as we do in C programming language.Older C++ compilers still need ".h"extension.
Newer compilers don't need that extension.For most of the programmes in C++ we use"iostream",it provides methods to take the input and print the output to the console. 

   2. using namespace std;

Here namespace is a special keyword used in C++. Here we are using std namespace . The compiler will check for classes,functions in the standard library.All of the standard library definitions are inside namespace std.

If we don't use standard namespace ,you need to write "std" behind every keyword.
ex-
std::cout<<"hello world"<<endl; 

  3.int main()

main() function is the starting point of a c++ program.
here {................},
these braces denotes the function body.

cout<<"hello world"<<endl;
cout is used to write the output to the console and endl is used to put a new line.


AFTER COMPILING AND RUNNING THE PROGRAM OUTPUT IS:



No comments:

Post a Comment

CHAPTER-2(PART -1 C++ Input Output)

 In C++ input and output occurs in stream of bytes. If the stream of sequence of bytes go from keyboard to the main memory is called as inpu...