Write your first program. The output of the program will be Hello world!

 


 Write your first program. The output of the program will be Hello world!

This is your first program in c++. This is your programming journey starts. This code just print Hello world !  as output.

 //Best of luck .Do Not Give Up .learning new things always takes time  
 #include<iostream> //This is header file .We have to include becasue we are using cout cin   
 using namespace std;  
 int main()//Your main function   
 {  
   cout<<"Hello world "<<endl; // What you write in side cout it always print in screen  
 }  
Ouput
Hello world !
Analysis of your Source code
  • #include<iostream> this line of code include header file iostream . This is the need for input and output operations in your code
  • # is preprocessor directive.
  • int main() is a function name as main.
  • cout<< is stander output
  • endl is used to end the line and start the next line from the start
  • Extra Information
    A program is a collection of various functions, such as main we will discuss complete chapter about function, but for now, just remember function is a collection of a statement or we can say the line of codes. This gives permission to use some predefined object (the object we will study in the class chapter ) like cout , cin, cerr a many more.

    Header File or #include<iostream>
    In your code all line begins with # is dedicated to the preprocessor. For now, trust me it's not really important to understand. Just remember something is there you can see this but do not understand like the sun. Still, our scientists are struggling to know more about the sun.
    So #include<iostream> should be first-line this is important.This is used for basic input-output library in Operator overloading we will visit this concept deeply. its asked to compiler please add include standard iostream file with this code.

    using namespace std;
    Every element of standard C++ is defined under a certain place, called a namespace. This imported namespace into your code. If you are using this statement for starting time this is very helpful but it takes a little longer time to run the program because you are not using the whole namespace so a better option is use std::cout or std::cin .

    int main()

    This line used to name function name which returns an integer. The function is a very big concept in any programming language we will read it later. This line is the beginning of the main definition of our code, or this is where execution will start. It really does not matter where you write for example in class you defined the whole class then using int main(), every C++ its important main() function used.

    0 Comments