"Introduction to C++"

Introduction to C++ -for beginners.

Generally speaking, for conveying some message or to interact with someone we use Language as a medium.

Similarly, to communicate with a computer we need a language. There are different types of languages which are used to provide a set of instructions to a computer, they are known as  Programming Languages.

Programming languages are classified into 3-types:

1. Low-level programming language: -

In this type of programming language, the communication with the system is in the binary format, (i.e., 0's and 1's) which can be directly executed. These low-level programming languages provide instructions that can be used to perform low-level operations like memory management, etc.

   example: - assembly language and machine language.

2. Middle-level programming language: -

In this type of programming language, the communication with the system is in the form of English text which is easily readable/understandable by humans

   example: - C-language, C++ and java is few examples of Middle- level programming languages.

3. High-level programming language: -

These are the languages that support both features of low-level and Middle-level. These are also written in human-readable text. They typically use tools like compilers to convert the human-readable instructions (high-level language constructs) into low-level executable code (usually in binary format).

   example: - python, javascript, ruby, PHP, Perl, C# are few examples of High-level programming languages.

  • C++ is a type of Middle-level computer programming language.
  • Here In this blog, I would like to discuss with you the basics of C++!

  • C++ was created by Bjarne Stroustrup as an extension of programming language C.

  • C++ is similar to c which is a procedural language.

Let us understand, a basic program to print “I’m learning C++ “ in C++ programming language.

Program: -

#include <iostream>

using namespace std;

int main() {

cout << "I'm learning C++\n";

}

Program to print "Hello" in C++
Basic C++ Program to print "I'm learning C++".


Output: -

                          I’m learning C++

output of C++ program in console
The output of the given input C++ program.

Explanation: -

In the first line of the above code: -

“#” - preprocessor directive.

“include” – is a command.

“iostream” – is a header file.

“< >” – this angle brackets advise the compiler to search for the document in the standard library.

The header file contains a bunch of templatized input/output classes.

iostream utilizes the objects in cin, cout, cerr, and clog for sending data to and from the standard input, output, error(unbuffered), and log(buffered) separately.

General syntax: -

#include <header_file_name>


In the second line of the above code: -

“using” – using means you are going to use it

“namespace” – is a compartment for a set of elements in which each element has a name unique to that set.

“std” – is a namespace where features of the C++ standard library, such as string or vector are declared.

“;” semicolon is a comand; it lets the compiler to know that it has arrived at the finish of a command. At the end of each statement, it is mandatory to out a semicolon.


In the third line of the above code: -

“int main()” – it consists of two pars int are the return type and which means the function main() returns integer data value, and main() is a function (subroutine) that is called by the operating system. main() is always the starting point of execution in any C++ program.

“{“– the code will be written within the opening brace.


In the fourth line of the above code: -

“cout" – it is used to produce output on the standard output stream device which is usually the display screen.

“<<” – it is called as an insertion operator,

“ “I’m learning C++” “– the double quotes are used for string literals, the information written in between double quotes prints the same in the output. 

“\n” – it is an escape sequence; this is used to break the output result line after printing the current line. It is also known as a new line character.


In the fifth line of the above code: -

“}” – the code block end with a closing brace.

Code block: - a code block starts with an open brace ” and ends up with closing brace }, in C++ the executable statements are written in code blocks. 

 

Let’s discuss some important term’s in C++:-

“source code, source file, compiler, linker, executable file”: -

The code written in C++ is called “source code” or “code”.

The source code saved to a file with the “.cpp” extension is called a source file.

Compiler is a special program designed to compile a source file. The source file after compiled, creates an object file with “.obj” extension if there is no syntax error.

Linker is another program is used to combine one or more object files to create a single executable file. The created executable file can have the extension “.exe” (in windows).

 

 Conclusion: -

Taking everything into account,  I believe that this blog post would give you basic information about types of programming languages and the structure of a basic C++ program.  Additionally, the blog also helps you in realizing some significant terms like source code, source file, compiler, linker, and executable file.

"THANK YOU!" 


Comments

Popular