Learn Basic Structure of C++ Programming Language

Learn Basic Structure of C++ Programming Language: Hello, everyone, if you have just started learning to code, then this blog will help a lot, Learning C++ programming is very important for beginners. In this article, we will discuss the basic structure of the C++ programming language, including its syntax, data types, and control structures.

C++ Programming Language History?

C++ is a powerful, high-performance programming language that is widely used in a variety of applications. It was developed in the early 1980s by Bjarne Stroustrup as an extension to the C language. C++ is an object-oriented programming language, which means that it uses classes and objects to structure code.

Features of C++ Programming Language

  • C++ is an object-oriented programming Language
  • Simple
  • Portability
  • Powerful    
  • Platform dependent    
  • Object Oriented Oriented
  • Case sensitive
  • Compiler based    
  • Syntax based language
  •  Use of Pointers Etc.

What are the uses of C++ programming language?

  • Design operating systems like Windows.
  • Google uses C++ for indexing.
  • apple os uses a few parts of C++ for OS X.
  • some browsers develop in C++ language like Firefox.
  • some applications or software Design in C++ like adobe systems, Photoshop, ImageReady, Illustrator, and Adobe Premier.
  • Design Language Compiler
  • Design Database
  • Utilities
  • Games
  • Application Software
  • Google applications are also coded in C ++, including Google File System and Google Chromium Etc.

Learn Basic Structure of C++ Programming Language Program – syntax of C++ program

The syntax of C++ is similar to that of the C language. It uses curly braces to define code blocks and semicolons to terminate statements. Here’s a simple “hello friends” program in C++:

#include<iostream.h> //this is header file 
using namespace std; // C++ library routines are kept in the standard namespace
int main()//this is main function start compiler read a program here 
{ 
cout<<" hello friends"; // print screen function 
return 0; // return function 
}

OUTPUT:

 hello friends

 

first prgram in c language darkwiki 1

Here’s another simple “Hello, World!” program in C++:

#include <iostream>
using namespace std;

int main() {
cout << "Hello, World!" << endl;
return 0;
}
Output: Hello, World!

Let’s break this code down. The first line is a preprocessor directive that tells the compiler to include the iostream header file. This file contains definitions for the input and output streams that we will use to display text in the console.

The next line uses the “using” keyword to specify the std namespace. This allows us to use the “cout” and “endl” objects without having to prefix them with “std::”.

The “main” function is the entry point of the program. It has a return type of “int”, which indicates that it will return an integer value when it finishes executing. The curly braces define the code block for the function.

The “cout” object is used to display text in the console. The “<<” operator is used to insert the text “Hello, World!” into the output stream. The “endl” object is used to insert a newline character into the output stream.

The “return” statement at the end of the function indicates that the program has finished executing and will return a value of 0 to the operating system.

Data Types in C++ Programming Language

C++ has several built-in data types that can be used to store different kinds of values. Here are some of the most common data types:

  • int: Used to store integer values.
  • double: Used to store floating-point values with double precision.
  • char: Used to store single characters.
  • bool: Used to store boolean values (true or false).
  • string: Used to store sequences of characters.

Here’s an example of how to declare and initialize variables of different data types:

int myInt = 42;
double myDouble = 3.14159;
char myChar = 'a';
bool myBool = true;
string myString = "Hello, World!";

Data type Keyword in C++ Programming

  • Boolean                                               bool
    
  • Character                                             char
    
  • Integer                                               int
    
  • Floating point                                        float
    
  • Double floating point                                 double
    
  • Valueless                                             void
    
  • Wide character                                        Wchar_t

Control Structures in C++ Programming Language

Control structures are used to control the flow of execution in a program. C++ has several types of control structures, including:

  • if/else: Used to execute code conditionally based on a boolean expression.
  • for Used to execute a block of code a fixed number of times.
  • while: Used to execute a block of code as long as a boolean expression is true.
  • do/while: Used to execute a block of code at least once, and then repeatedly as long as a boolean expression is true.

Here’s an example of an if/else statement:

```
int myInt = 42;
if (myInt == 42) {
cout << "The answer to the ultimate question of life, the universe, and everything is " << myInt << endl;
} else {
cout << "Sorry, wrong answer." << endl;
}
```

This code checks whether the value of “myInt” is equal to 42, and displays a message accordingly.

Here’s an example of a for loop:

for (int i = 0; i < 10; i++)

Variables in C++ Programming Language

Variables are used to store values in memory that can be accessed and manipulated in a C++ program. In C++, variables are declared using a specific data type, which determines the size and type of data that can be stored in the variable.

a = 10;
b = 20;
c = 30;

Array in C++ Programming Language

Data type ki value ka collection ko array kaha jata hai, inko Ek hi name se represent kiya jata hai, array ki value fix hoti hai inhe change nahi kiya jata. array kuch iss trah likha jata hai.

char darkwikiarray[5] = {'d','a','r','k','w','i','k','i'};

Comment in C++ programming Language

Comments in C++ are used to provide information and explanations about the code to other programmers or to remind yourself of the purpose of certain sections of code. Comments are ignored by the compiler and do not affect the execution of the program.

Types of Comment in C++ Programming Language

  • single line comment (// single line comment )
  • multi-line  comment (/*multi-line  comment*/)

Constant in C++ programming Language

In C++, a constant is a variable that cannot be changed once it has been initialized. Constants are useful when you want to define a value that should remain constant throughout the program or to prevent accidental changes to a variable’s value. using constants in your C++ programs can help make your code more readable, easier to maintain, and less prone to errors.

Types of constants in C++ programming

  • Integer constant
  • Floating-point constant
  • Boolean constant
  • Character constant    
  • String constant
  • Defining Constants
  • The #define Preprocessor
  • The const keyword.

C++ Programming Language Compiler Free Full Version Download

Download some free C++ coding language compilers. A C++ compiler is a program that translates C++ source code into executable programs.

Download C++ programming language Ebook: click here

Best online website for Learn c++ programming language

Related: 

Best C Programming Language Online Free Course

Best Free Python Programming Online Course

Best C++ Programming Free Course with Certificate

Co-Founder & Author - darkwiki.in I am a Technical blogger with over 3 years of experience. I am passionate about blogging, Coding, and YouTube videos. I love gaming.