C language is a procedure oriented programming language
Its is partially object oriented programming language
It follow top-down approach
It 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 functions
This language supports both virtual and friend functions
C language have 32 keyword
This language have 52 keyword
Advantages and disadvantages in Cpp
Feature
Advantage
Disadvantage
Code reusability
Techniques like OOP, templates
Manual memory management
Standardization
Standardized every 3 years
Performance and code size can be an issue
Compatibility
Code can work across multiple devices/platforms
Feature rich and can be difficult to learn
Performance
Code size and performance can be better than C
Code can be difficult to maintain
Support
Great support and tools available for embedded developers
Modern features
Modern 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