A specific template structure is used to write the C++ program. Let us see an example of “Hello World” program.
#include <iostream>
using namespace std;
int main() {
// Write C++ code here
cout << "Hello world!";
return 0;
}
Hello world!
The C++ programming language defines several headers, each of which contains information that is either required or useful to your program. The header <iostream> is required for this program.
Using namespace std; instructs the compiler to use the std namespace. Namespaces are a relatively new feature of C++.
The line int main() is the main function where program execution begins.
// Write C++ code, here is the single-line comment in this program that is not executed by the compiler.
The following line cout “Hello World”; displays the message “Hello World” on the screen.
The following line return 0; terminates the main() function and causes it to return 0 to the calling process.
In C++, a class is defined by using the keyword class followed by the class name. The curly brackets define the body of the class, which is followed by a semicolon. Let us take an example:
#include <iostream>
using namespace std;
class Coderz
{
int i; //data variable
void print() //Member Function
{
cout << "Inside Member Function of coderz";
}
}; // Class ends here
int main()
{
Coderz obj; // Creatig Coderz class's object
obj.print(); //Calling member function using class object
}
This is how a class is defined; after defining a class, its object is created and its member functions are used.
Variables can be declared anywhere in the program, but they must be declared before they can be used. As a result, we don’t need to declare variables at the beginning of the program.
Note: also read about the OOPs Concepts in C++
If you like my post, please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…