Learn C++ Programming
“C++ is a statically-typed, free-form, (usually) compiled, multi-paradigm, intermediate-level general-purpose middle-level programming language.”
In simple terms, C++ is a sophisticated, efficient and a general-purpose programming language based on C. It was developed by Bjarne Stroustrup in 1979.
Many of today’s operating systems, system drivers, browsers and games use C++ as their core language. This makes C++ one of the most popular languages today.
Since it is an enhanced/extended version of C programming language, C and C++ are often denoted together as C/C++.
History of C++
While Bjarne Stroustrup was working in AT&T Bell Labs in 1979, he faced difficulties in analyzing UNIX kernel for distributed systems. The current languages were either too slow or too low level. So, he set forward to create a new language.
For building this language, he chose C. Why C? Because it is a general purpose language and is very efficient as well as fast in its operations.
He used his knowledge of object-oriented model from SIMULA and began working on class extensions to C. His aim was to create a language with far higher level of abstraction while retaining the efficiency of C.
This new programming language was named C withClasses, but was later renamed to C++ (++ refers to the increment operator in C).
important features you should know.
- C++ is fast
Since, C++ is an extended version of C, the C part of it is very low level.
This offers a huge boost in speed that high level languages like Python, Java don’t give you.
- C++ is statically typed
C++ is a statically typed programming language.
In simple terms, C++ doesn’t allow the compiler to make assumptions about the type of data e.g. 10 is different from “10” and you have to let C++ know which one you are talking about.
This helps the compiler catch errors and bugs before execution of the program.
- C++ is a multi-paradigm programming language
C++ supports at least 7 different styles of programming and gives developers the freedom to choose one at their will.
Unlike Java and Python, you don’t need to use objects to solve every task (if it’s not necessary).
You can choose the programming style that fits your use case.
- Object oriented programming with C++
Object oriented programming helps you solve a complex problem intuitively.
With its use in C++, you are able to divide these complex problems into smaller sets by creating objects.
- Power of standard library (Standard template library - STL)
The power of C++ extends with the use of standard libraries contained in it.
These libraries contain efficient algorithms that you use extensively while coding. - Now you have installed the compiler based on your OS, it’s time to write your first C++ program.
“Hello World!”
Your first C++ program will be a “Hello World!” program.You might have noticed “Hello World!” being the first program while starting out with any programming language. This is because:- It is a standard check to see whether everything is working fine or not.
- There will be very less code to start with.
- The less code makes it intuitive for the beginners to get acquainted with the language.
- The code is enough to learn the basic syntax and semantics of the language.
So, let’s get coding.#include <iostream> using namespace std; int main() { cout<<"Hello World!"; return 0; }
The program printsHello World!
in the output screen.How the program works?
Now, let’s dissect the above code. The code is divided into six major parts:- #include <iostream>
- using namespace std
- ;
- int main() { }
- cout << “Hello World!”;
- return 0;
- What is #include <iostream>?
If you’ve already written code in C language before, you might seen this line of code before. If you haven’t, don’t worry we’ll cover it now.
This statement includes the header file into the application so that you are able to use the operations included in them. Also, you can create your own header files and include them in your program using the#include
.
What is iostream?iostream
is what you call the header file. It is a standard C++ input/output library file.
It comes packaged with the compiler/IDE and contain mechanisms to get the information from the user and print same or added information to a file, screen or any other media.The#include
iostream file, into the program. This ensures that now you’re able to use the operations,iostream
operations (like: taking input from user, displaying output on the screen), in the program. - What is using namespace std;”?
The statement is intuitive in itself, you are “using” the “namespace” “std” in your file.
We use thenamespace std
to make it easier to reference operations included in that namespace.
If we hadn’t used the namespace, we’d have written std::cout instead of cout. This tells the compiler that every cout is actually std::cout.
What’s a namespace?
It’s a region where your code resides. It limits or expands the scope of your code to one or more files.
Why do you use namespace?
Like two persons can have the same name, variables and functions in C++ can have same names as well. The use of namespace is to avoid the confusion of which variables/functions you are referencing to.
What is std?std
is a standard namespace used in C++. - Semicolon ”;”
Ask any C++ programmer and they will tell you at least one horror story related to the semicolon ; .
The semicolon is a terminal. It terminates a statement. When missed or incorrectly used, it will cause a lot of issues. - int main() { }
As the name suggests, it is the main function of the program. The code inside { } is called the body and is executed first when you run your C++ program.
It is one code that is mandatory in a C++ program. If you just have this line of code alone, your program will be valid. - cout << “Hello World!”;
This statement prints “Hello World!” onto the output screen.
Thecout
is an object of standard output stream. What this means is, it outputs/prints the data after << , i.e.Hello World!
into a stream (in this case, the output screen).
What is a stream?
Stream is basically a sequence of objects, usually bytes. It can describe files, input/output terminal, sockets, etc.
What is <<?<<
is the insertion operator used to write formatted data into the stream. - What is return 0;?
This statement returns 0 ‘zero’.
This is called a return statement. It isn’t mandatory to return anything from the main() function but is rather a convention. If not return, the compiler returns a status automatically.
Why zero in return statement?
It denotes Exit status of the application that basically the tells system “The program worked fine.”
FLOW CONTROL
- if...else
Statement
- for
Loop
- do...while
Loop
- break
& continue
- switch
Statement
- goto
Statement
FUNCTIONS
- C++
Functions
- Function
Types
- Function
Overloading
- Default
Argument
- Storage
Class
- C++
Recursion
STRUCTURES
- Structure
- Structure
and Function
- Pointers
to Structure
- Enumeration
ARRAYS & STRING
- C++
Arrays
- Multidimensional
Arrays
- Function
and Array
- C++
String
OBJECT & CLASS
- Objects
and Class
- C++
Constructors
- Objects
& Function
- Operator
Overloading
INHERITANCE
- C++
Inheritance
- Function
Overriding
- Multilevel
Inheritance
- Friend
Function
- Virtual
Function
- Templates
C++ "Hello, World!" Program |
C++ Program to Print Number Entered by User |
C++ Program to Add Two Numbers |
C++ Program to Find Quotient and Remainder |
C++ Program to Find Size of int, float, double and char in Your System |
C++ Program to Swap Two Numbers |
C++ Program to Check Whether Number is Even or Odd |
C++ Program to Check Whether a character is Vowel or Consonant. |
C++ Program to Find Largest Number Among Three Numbers |
C++ Program to Find All Roots of a Quadratic Equation |
C++ Program to Calculate Sum of Natural Numbers |
C++ Program to Check Leap Year |
C++ Program to Find Factorial |
C++ Program to Generate Multiplication Table |
C++ Program to Display Fibonacci Series |
C++ Program to Find GCD |
C++ Program to Find LCM |
C++ Program to Reverse a Number |
C++ Program to Calculate Power of a Number |
Increment ++ and Decrement -- Operator Overloading in C++ Programming |
C++ Program to Subtract Complex Number Using Operator Overloading |
C++ Program to Find ASCII Value of a Character |
C++ Program to Multiply two Numbers |
C++ Program to Check Whether a Number is Palindrome or Not |
C++ Program to Check Whether a Number is Prime or Not |
C++ Program to Display Prime Numbers Between Two Intervals |
C++ Program to Check Armstrong Number |
C++ Program to Display Armstrong Number Between Two Intervals |
C++ Program to Display Factors of a Number |
C++ Programs To Create Pyramid and Pattern |
C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch...case |
C++ Program to Display Prime Numbers Between Two Intervals Using Functions |
C++ Program to Check Prime Number By Creating a Function |
C++ Program to Check Whether a Number can be Express as Sum of Two Prime Numbers |
C++ program to Find Sum of Natural Numbers using Recursion |
C++ program to Calculate Factorial of a Number Using Recursion |
C++ Program to Find G.C.D Using Recursion |
C++ Program to Convert Binary Number to Decimal and vice-versa |
C++ Program to Find Largest Element of an Array |
C++ Program to Find the Number of Vowels, Consonants, Digits and White Spaces in a String |
C++ Program to Remove all Characters in a String Except Alphabets. |
C++ Program to Find the Length of a String |
C++ Program to Concatenate Two Strings |
C++ Program to Copy Strings |
C++ Program to Add Complex Numbers by Passing Structure to a Function |
C++ Program to Calculate Difference Between Two Time Period |
C++ Program to Store and Display Information Using Structure |
No comments:
Post a Comment