Basic Syntax of CPP Language. It is understood that the C++ program can be a bit difficult to know because it is a collection of objects. It is generally communicated by requesting each other’s methods. Allow us to check out the parts of the syntax that object, class methods, and instance variables mean:
Class:
A class in C++ is the building block that results in Object-Oriented programming. Basic Syntax in c++. It is a collection of objects with the same properties and functions. Class is used to define the characteristics of the objects. For Example, A class Person can be used to define the characteristics and functions of a person. It can be used to create many objects of type Person such as Ali, Rauf, Usman, etc.
Each object of a class is known as an instance of its class. For Example, Ali, Rauf, and Usman are three Instances of a class Person. Similarly, my book and your book can be two instances of a class Book.
Object:
Objects represent an entity in the real world such as a figure, things or concepts, etc. An object can be identified by its name. An object consists of the following two things.
Properties: Properties are the characteristics of an object.
Function: Functions are the activities that can be performed by an object.
Method:
Any behavior is called because of the methods in C++. Methods are called the foremost important. A part of the C++ as all the operations like writing logics, manipulating data actions execute. There will be numerous methods in a very class.
Instance Variable:
The state of an object is normally by the values that are allocated to the instance variables as each object has its own unique set of instance variables.
Example of C++ Syntax:
#include <iostream> using namespace std; // main() is where program execution begins. int main() { //you can use here 'void main()' cout << "Hello World"; // prints Hello World return 0; }
Briefly Explain Basic Syntax CPP above Program:
#include <iostream> |
---|
Preprocessor directive is an instruction stated to the compiler before the execution of real program. Preprocessor directive is also called as compiler directive. It is a part of compiler. The preprocessor directive start with hash # sybol.Include preporocessor directive used to include header files in the program. The syntax of using this directive mentioned above.
using namespace std; |
---|
Namespaces are used to sort code into the logical category and to intercept name collisions that can happen mostly when your codebase includes multiple libraries.
All identifiers at the namespace range are visible to one another without qualification. Identifiers externally the namespace can approach the members by using the fully qualified name for each identifier,
int main() |
---|
The Int main() is a function where the program start execution.
cout<<“print”; |
---|
Cout stand for Console Output. It is used to print a value on the screen.
return 0; |
---|
The reutn0; function use to terminate the function. It means all the things are going on the way.
Learn : Learn C++ Basics: