Welcome back, fellow hackers! in this tutorial, we will switch from C to C++, learn how to use C code in our C++ programs, and a quick introduction to comment lines and why they are so useful.
Why C++ and Not C?
simple: because C++ is more powerful. also, the syntax of C++ is almost identical to C. the only big difference are the instructions. in C++, the printf equivalent is named cout. we will mostly be focusing on C++ from now on, but we will do some C too. as i said before, if you know C++ syntax you know C syntax too.
alright, now, let's get started!
Step 1: Fire Up Ubuntu and Open a Text Editor
once you have Ubuntu up and running and have a text editor open, pastethis code in it. then save it as main.cpp. MAKE SURE YOU NAME IT EXACTLY LIKE THIS!.
Step 2: Compile Using G++
compiling a C++ program is the same as compiling a C program, except one thing: we need to use the g++ command. this still belongs to GCC, but is the command to compile C++ programs. you can remember this by knowing the C's in "gcc" stand for C, and the pluses in "g++" stand for the pluses in C++. just run this command like we are compiling a C program using gcc.
g++ main.cpp
if everything goes alright, we will get a a.out file again.
Step 3: Run
to run our freshly compiled program, simply type this in your terminal:
./a.out
Remember that you need to allow execution privileges first!
then our program will print out "Hello Null Byte!" on the screen, just like in our C program.
Explanation Time!
alright, as we can see, we have 3 new lines, the other lines we already saw in our C program. i will explain them one by one.
#include <iostream> this is the equivalent to #include <stdio.h> in our C program, except that the library is named differently here. you may recognize "io" in both, which stands for input/output. this means that the iostream library holds all the input/output instructions of C++. (also, take note that we don't have to provide a .h extension in this library).
using namespace std; this is something extra we need to use in C++. it tells us what namespace to use from our libraries. a namespace is basically something in a program that groups instructions and functions together. here, when we use the "using" instruction, we tell our compiler to use the namespace std (which stands for "standard"). this namespace holds the standard I/O instructions, like cout.
cout << "Hello Null Byte" << endl; this is the equivalent to printf in C programs. instead of using a parameter (we will talk about that later, it is the value that you place in between the ( and ) of a function), we need to use 2 << to then specify our string to print out. after that, we can specify even more strings or even a cout command, called endl. this will just end the line, and is the equivelant to \n in C programs (you can still use \n in the same way as in C programs, by the way).
Run C Code in C++ Programs
this is simpler than you would think. you just need to #include the C library you want to use! here is an example. go ahead and delete your previous a.out, open up main.cpp, delete everything and replace it with this code. then save it and recompile it again using g++. then run the new a.out. as you can see now, we get one line printed by the printf function from C and one line by the cout function from C++!
"Why Would You Even Run C Code in C++? I Thought C++ Was More Powerful!"
yes, it is. but it doesn't have all the instructions of C. for example, the System() instruction, which allows you to execute system shell commands (i'll talk about that later.). another example would be if you found an external library and it was only developed for C.
Comment Lines
comment lines are simply lines in your program that the compiler will completely ignore. these lines are great to explain what you are doing in your program to other programmers. to make a comment line, simply type 2 slashes (//) and after that your message. here are some examples:
//This is the instruction that will print out text on the screen
//This is the main function
//This is the main function
when you type these lines in your code, the compiler will just ignore them. this is also great for debugging your code, as it allows you to temporarily disable an instruction without completely removing it.
that is it for now folks! in the next tutorial, we will learn about variables.
if you have any questions or problems, feel free to comment them down bellow or PM me!
-Phoenix750
This professional hacker is absolutely reliable and I strongly recommend him for any type of hack you require. I know this because I have hired him severally for various hacks and he has never disappointed me nor any of my friends who have hired him too, he can help you with any of the following hacks:
ReplyDelete-Phone hacks (remotely)
-Credit repair
-Bitcoin recovery (any cryptocurrency)
-Make money from home (USA only)
-Social media hacks
-Website hacks
-Erase criminal records (USA & Canada only)
-Grade change
-funds recovery
Email: onlineghosthacker247@ gmail .com
Do you need to increase your credit score?
ReplyDeleteDo you intend to upgrade your school grade?
Do you want to hack your cheating spouse Email, whatsapp, Facebook, instagram or any social network?
Do you need any information concerning any database.
Do you need to retrieve deleted files?
Do you need to clear your criminal records or DMV?
Do you want to remove any site or link from any blog?
you should contact this hacker, he is reliable and good at the hack jobs..
contact : cybergoldenhacker at gmail dot com