c++ programming introduction

C++ Programming Introduction

Hi Hello, Welcome to my blog

Today, I will be planning to start a C++ Series playlist where we can explore C++ Concepts from basics to advance and key concepts and implementations which will be used in real world. Later I will be showing how we can use C++ in Embedded systems world.

Introduction

C++ is a statically typed compiled and Objected Oriented High Performance programming language, C++ is developed and created by BJARNE STROUSTRUP in 1979 at AT&T Bell Labs.

When C++ Is initially developed for the superset of C, which means that any C programs is also a valid C++/Cpp Programming language but it also add zero overhead abstractions such as object-oriented patterns like polymorphmism, encapsulation and inheritance and today C++ is used in a wide variety of software systems with constried memory demands and high performance applications and also in Embedded systems, networking and Gaming developments

It is also propular because C++ also provided low-level memory and hardware control like C with high abstractions like classes and objects.

Basic Things needed for to Execute a Simple C++ Program

We can say that 2 important things required for a program

  • Like C Program stdio.h, In C++ we have to use iostream to include all the input and output required api’s. Abbreviation for iostream is called as input output stream. If we need to use input and output functionalities like if we to get a input from user and to provide output to the terminal such as debug logs for these purpose we have to include iostream header file so that compiler will import those supported functionalites to the C++ Program
  • 2nd thing we need is using namespace std;
    • std is a supported library which we need to use ready-made API like cout, cin and endl. These belong to std library
    • you can think std as a container or box where C++ keeps its built in tools
    • difference between both, iostream is a file that we are going to include and std is a library which we are going to use that is major difference in these 2 statements

With and Without Using the “using namespace std”

without “using namespace std”

  • if we don’t include using namespace std, then everytime when we use cout we must write like this
    • std:: cout << “Hello World Welcome to ChipNCode”
    • same goes for cin, endl and many other things

with “using namespace std”

  • We are telling compiler that, whenever i use cout or cin, just look inside std automatically.
  • So we can write simply
    • cout << “Hello World Welcome to ChipNCode !!!”;

Hello World C++ Program

#include <iostream>
using namespace std;

int main()
{
     cout << "Hello World Welcome to ChipNCode!" << endl;

     return 0;
}

What is Function, and Why it is used in C++ Program

To do a dedicate functionality, to explain the compiler and set of job and statements to execute

also we can say that function is called a block of code that does a specific job. Instead of writing the same code again and again we can put the specific set of statments/tasks in one function and we can call the particular function wherever and multiple times required.

In C++ Program, main function is important that’s where first line of user statements starts to execute. but most people think that main is the function line of code computer or any microcontroller or processor will execute that is not a case, certain steps will be execute before main calls. those things are listed below

  • Startup code will be excecuted before main function will be called
    • During Startup code, when computer or controller boots up first thing it will do is to initialize the stacks
    • Disable all the interrupts
    • copy and paste the initialized data from ROM to RAM
    • Enable interrupts
    • Initialize the heap
    • Constructions execution
    • Main Call

User statements and user functions will starts execute from main function.

Why “int main” int data type is used before main ?

We have to tell the compiler that main is executed successfully or not. Compiler excepts some return value after executing the main function. Usually if 0 returns then compiler understands main executed without any errors. Also integer is data type to be returned though values can be – or +. Later series we can see deeply about datatypes and value limits

Some Important Points to be remember

; –> Semicolon represents termination of statement

// —> Comments for comments there is no semicolon required

multiple cout can be executed with help of endl; endl full form: end line. Without using endl, our compiler will execute immediately on the next statement without going next line. To tell the computer or compiler to execute on next line.

cout – is an object

endl is a manipulator

<< – stream insertion operator

\n – Code for new line

\r – Carriage return goes to start of the same line

\t – tab space

\b – backspace

\\ – backslash

\” – prints double quote

\’ – prints single quote

\0 : Null character

Leave a Reply