C++

From Mario Fan Games Galaxy Wiki
Revision as of 05:48, 8 December 2016 by Q-Nova (talk | contribs) (Added a little bit of info about its use on MFGG. It makes it no longer a dead-end.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

C++ is a cross-platform programming language that is widely used in the programming world; everything ranging from games to operating systems are coded in C++. C++ is a slightly higher-level derivative of C, sharing mostly the same syntax while adding many more features, notably native support for object-orientation. C++ is known to be extremely difficult to learn to many people; it not only has hundreds of libraries (each with their own API designs), but it has complicated syntax, which can be customized to an extent to suit a programmer's needs.

C++ is one of the fastest languages, and along with C, is usually the language used to create other languages. Being relatively low-level, programmers have direct access to memory and computer hardware, which is usually not possible with scripting languages. However, pushing the burden of memory management onto the programmer can lead to memory leaks in badly-written code. In contrast, scripting languages usually handle memory by themselves through garbage collectors, but this generally has a large performance hit.

Despite its speed, many programs are now phasing out using C languages for most tasks, instead using scripting for the bulk of the program. Scripts are generally easier to read and maintain, and most can call C functions should a task need to run as quickly as possible. Scripts can also be loaded and executed during runtime, which can't be done with C++ because it has to be compiled first.

On MFGG, quite a very few amount of members have been known to mainly program in C++.

C++ Example: Hello World!

Code

 #include <iostream>
 using namespace std;
 int main()
  {
  cout << "Hello World!";
  return 0;
  }

Explanation

Line 1: #include <iostream>: This includes all of the C++ functions required for console input/output.

Line 2: using namespace std: This tells the compiler to use the default namespace, which constains the iostream commands like cout and cin. Otherwise, you would have to prefix commands like cout and cin with "std::" (for example, std::cout).

Line 3: int main(): This creates the main function, which is what the program runs in. The main function always must return an integer (int), and that int must be zero when you want to end the program without error.

Line 4: {: This starts the block of code for the main function.

Line 5: cout << "Hello World!";: This displays the text "Hello World" in the console window.

Line 6: return 0;: This tells the main function to end without error. If this code is not included somewhere in the main function, the compiler will return an error.

Line 7: }: This ends the block of code for the main function.