C++ Introduction

use more keyphrases or synonyms in your H2 and H3 subheadings

Difference between C and C++

CCpp
C language is a procedure oriented programming languageIts is partially object oriented programming language
It follow top-down approachIt follows bottom-up approach
It doesn’t support function or operator overloading It doesn’t support function as well as function overloading
C language doesn’t support virtual and friend functionsThis language supports both virtual and friend functions
C language have 32 keywordThis language have 52 keyword

Advantages and disadvantages in Cpp

FeatureAdvantageDisadvantage
Code reusabilityTechniques like OOP, templatesManual memory management
StandardizationStandardized every 3 yearsPerformance and code size can be an issue
CompatibilityCode can work across multiple devices/platformsFeature rich and can be difficult to learn
PerformanceCode size and performance can be better than CCode can be difficult to maintain
SupportGreat support and tools available for embedded developers
Modern featuresModern language with modern features

Hello World

Example-1

#include <iostream>

using namespace std;

int main()
{
    cout<<"ArunEWorld";

    return 0;
}
  • Output: ArunEworld
  • Here
    • cout – console output

Example-2

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string name = "ArunEworld";
    cout<< name <<endl;

    return 0;
}
  • Output: ArunEworld
  • Here
    • endl – end line
    • string is the data type or container can hold the string variable.

Namespace

What is namespace in cpp?

  • A namespace is a group of related elements that each have a unique name or identifier.
Namespace Example

Why namespace is required in cpp?

  • Answer will be added

Data Type

  • char – Single character
  • string – Multiple characters
  • int – Whole numbers
  • float – Decimal numbers
  • double – Decimal numbers
  • bool – boolean values

String

Example-1

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string site = "ArunEworld";
    site[4]='P';
    cout<< site <<endl;

    return 0;
}
  • Output: ArunPworld
  • Here
    • site act as array,

Static Cast in Cpp

#include <iostream>
using namespace std;
int main()
{
    float pi_val = 3.14159;
    //int result = pi_val; // this is how you do in C
    int result = static_cast<int>(pi_val);
    cout << result <<endl;
}
  • Output: 3
  • Here : float value can typecast into integer value

Reference:

wiki

Please turn AdBlock off, and continue learning

Notice for AdBlock users

Please turn AdBlock off
Index

Discover more from ArunEworld

Subscribe now to keep reading and get access to the full archive.

Continue reading