Hey everyone!
I'm excited to announce that I'm starting a blog series focused on Data Structures and Algorithms (DSA). I'll be sharing tutorials based on what I've learned and know.
I'll be using the C++ language for these tutorials, and I'll also be posting C++ language tutorials for those who are new to it.
C++ is a powerful, high-performance programming language that is widely used for system/software development, game development, and in applications requiring real-time processing.
It is an extension of the C programming language, adding object-oriented features and others.
Basics
- Download VScode .
- Download compiler (mingw) and add its path in environment variables. (To know more about please check this postπ) https://dev.to/mehfila_parkkulthil_23/how-to-setup-vs-code-and-1hng-temp-slug-1049206
- Install extension
C/C++ extension Pack
in vscode. - Create a folder or open a folder named
Projectss
. - Create a file as
myfirstfile.cpp
Basics of C++
- Code editor we are using here is Visual studio code.
- The extension of c++ is
.cpp
.
Syntax of C++
#include <iostream>
using namespace std;
int main() {
}
How the code works
*How to write code *
Anything written inside the curly brackets is gonna be executed .
ie,
For example : To print "Hello world "
, the word that has to be printed inside quotation marks.
#include <iostream>
using namespace std;
int main() {
cout << "Hello world" << endl;
return 0;
}
How to run code
- To run a C++ file, you'll need to have MinGW installed.
- Open new terminal in vscode .
- Type
g++ filename.cpp - o filename
./filename.exe
- Then enter.
\\ for windows users
g++ myfirstfile.cpp - o myfirstfile
./myfirstfile.exe
Explanation of code
#include <iostream>
: This line includes the input-output stream library, which is necessary for performing input and output operations.using namespace std
: You are informing the compiler that you are going to use the std (standard) namespace, so you don't need to prefix standard library entities withstd::
. And both works well .
;
- Every statement must end with a semicolon , it basically tells the compiler this line ends here ( same feature of fullstop.
in english language).int main()
: This line defines the main function, which is the starting point of the program. Every C++ program must have a main function.{ }
: These curly braces is the body of the main function, where the code to be executed is written .cout
(read as c-out) : is used to output data (or print) .The
<<
operator is used to insert the data into the output stream."Hello, World!"
is the string_(long form of text)_ that will be displayed on the console area .endl
- Used to insert a newline, moving the cursor to the next line.return 0
-This line indicates that the program has successfully executed and returns 0 to the calling process or operating system ( means has executed successfully without any errors or zero errors).
Top comments (0)