Beginning with c++ | Basic concepts of oop(c++)

 Programming codester 

Beginning with c++ :


Let's start with simple program: 

First of all solve the question:

in c programming header file is #include<stdio.h>,then in c++______(for i/o)

Wap to print “Hello world” in c++. 

 

Explanation: 

Line: 1: - In first line we write header file #include<iostream> that lets us work with input and output objects 

Line: 2: - using namespace std means that we can use names for objects and variables from the standard library. 

Line: 3: - int main (): -This is called a function. Any code inside its curly brackets {} will be executed. 

Line: 4: -  cout (pronounced "see-out") is an object used together with the insertion operator (<<) to output/print text. In our example it will output "Hello World". 

Line: 5: - return 0 ends the main function. 

NOTES: 

  • C++ ignore white spaces 
  • After main program start {brace and at the end program} brace must need 
  • If you want to avoid using namespace std Than u can use std:: 

 

Now let's see program features.  

Like C, the C++ program is a collection of functions. 

The above example contains only one function, main(). As usual, execution begins at main(). Every C++ program must have a main(). C++ is a free-form language. With a few exceptions, the compiler ignores carriage returns and white spaces. Like C, the C++ statements terminate with semicolons. 

  

Comments 

C++ introduces a new comment symbol (double slash). Comments start with a double slash symbol and terminate at the end of the line. A comment may start anywhere in the line, and whatever follows till the end of the line is ignored. Note that there is no closing symbol. 

 The double slash comment is basically a single line comment. Multiline comments can be written as follows: 

// This is an example of  

// C++ program to illustrate 

 // Some of its features 

 The C comment symbols/", "/are still valid and are more suitable for multiline comments.  

The following comment is allowed: 

/*This is an example of 

 C++ program to illustrate 

 some of its features*/ 

  

We can use either or both styles in our programs. Since this is a book on C++, we will use only the C++ style. However, remember that we cannot insert a // style comment within the text of a program line.   

 

Output Operator 

 The output operator is also known as the insertion operator (<<). Here, the treatment of data takes place as a stream of characters by cout. Furthermore, the flow of these characters takes place from the program to cout through the output operator. 

  

cout<<"C++ is better than C."; 

  

The statement causes the string in quotation marks to be displayed on the screen. This statement introduces two new C++ features, cout and <<. The identifier cout (pronounced as 'Cout") is a predefined object that represents the standard output stream in C++. Here, the standard output stream represents the screen. It is also possible to redirect the output to other output devices. The operator << is called the insertion or put to operator. It inserts (or sends) the contents of the variable on its right to the object on its left. 

 

The operator << is called the insertion or put to operator. It inserts (or sends) the contents of the variable on its right to the object on its left. 

  

The object cout has a simple interface. If string represents a string variable, then following statement will display its contents: 

  

cout<<<string; 

  

You may recall that the operator << is the bit-wise left-shift operator and it can still be used for this purpose. This is an example of how one operator can be used for different purposes, depending on the context. This concept is known as operator overloading, 

  

Variable 

It is important to note that we can still use printf for displaying an output. C++ accepts this notation. However, we will use cout << to maintain the spirit of C++. 

  

The iostream File 

We have used the following #include directive in the program: 

#include <iostream> 

This directive causes the preprocessor to add the contents of the iostream file to the program. It contains declarations for the identifier cout and the operator <<. Some old versions of C++ use a header file called iostream.h.The header file iostream should be included at the beginning of all programs that use input/output statements. Note that the naming conventions for header files may vary. Some implementations use iostream.hpp; yet others iostream.hxx. We must include appropriate header files depending on the contents of the program and implementation.  

 

So, Guys I hope you understood basic structure and concepts of c++. 

Related this topic video link here: 

I also uploaded basic program “Hello world” with c++ in my YouTube channel! 

I mentioned here! Check it out!! 

C tutorials: 

Thank you for your support! 

Learn and explore! 

 

 

  

Comments

Post a Comment

Popular posts from this blog

C programming | Printf and scanf ||

C programming | structure | Fundamentals of Structure

C programming | Fundamentals & Basic information

Basic question related programming || c programming || embedded programming

C++ || Operators with c++

C++ || string with c++ || Part - 1

Compiler & Interpreter | difference and explanation

c++|operators with c++|variables||

C programming | Nested structure | Array, function and pointer of structure|| structure Part-II

C++(oop)| Fundamentals | Concepts||