Topic 1 Introduction to C++ Programming
Topic 1 Introduction to C++ Programming
Computer Applications-2
2
C++
• Improves on many of C's features
• Has object-oriented capabilities
• Increases software quality and reusability
• Superset of C
• Can use a C++ compiler to compile C programs
• Gradually evolve the C programs to C++
C++
4
Similarities Between C And C++
• Both the languages have a similar syntax.
• Code structure of both the languages are same.
• The compilation of both the languages is similar.
5
Differences Between C And C++
• Language Type
C is procedural programming.
C++ supports both procedural and object-oriented
programming paradigms.
• OOPs feature Support
C does not support the OOPs concept so it has no support for
polymorphism, encapsulation, and inheritance.
C++ has support for polymorphism, encapsulation, and
inheritance as it is being an object-oriented programming
language
6
Differences Between C And C++
• Data Security
As C does not support encapsulation so data behave as a free
entity and can be manipulated by outside code.
C++ encapsulation hides the data to ensure that data
structures and operators are used as intended.
• Driven type
C in general known as function-driven language.
C++ is known as object driven language.
7
Differences Between C And C++
• Feature supported
C does not support function and operator overloading also do
not have namespace feature and reference variable
functionality.
C++ supports both function and operator overloading also
have namespace feature and reference variable functionality.
8
Differences Between C And C++
Header file used by C is stdio.h.
Header file used by C++ is iostream.h.
9
Differences Between C And C++
Namespace features are not present inside the C.
Namespace is used by C++, which avoid name collisions.
int main() {
// Your Programming statements HERE!
return 0;
}
11
First C++ program
// Simple C++ program
int main()
{
cout<<"Welcome to C++ Programming";
cout<<endl;
return 0;
}
12
C++ Program Structure
#include <iostream>
using namespace std;
// main() is where program execution begins.
int main()
{
cout << "Hello World"; // prints Hello World
return 0;
}
Let us look various parts of the above program:
• The C++ language defines several headers, which contain information
that is either necessary or useful to your program. For this program,
the header <iostream> is needed.
• The line using namespace std; tells the compiler to use the std
namespace. Namespaces are a relatively recent addition to C++.
C++ Program Structure
• The next line // main() is where program execution begins. is a
single-line comment available in C++. Single-line comments begin
with // and stop at the end of the line.
• The line int main() is the main function where program execution
begins.
• The next line cout << "This is my first C++ program."; causes the
message "This is my first C++ program" to be displayed on the screen.