Difference between revisions of "C++"

(Added example)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
C++ is a compiler language. A compiler converts between machine language and English. A compiler reads the program fully and creates a executable, which is composed of machine code. The executable can later be executed by the native system. An interpreter is a program that can process source code. The memory takes the form of a variable, with a value. Another value is returned from the ram to the hard drive using the return statement. If the function variable has type "void", no value is returned. Functions can be created and named, but if you name a function "main", make sure that it is supposed to be the first function to execute. The # include statement includes a file and its functions. Do not include a file if it has the main function. Most include files take the extension ".h", which is the extension for C++ header files. The C++ source file will have the extension ".cpp" or ".cc". The executable file will have the extension ".exe".
+
==Overview==
 +
C++ is a high-level programming language used for developing software. A compiler is responsible for translating the C++ code into machine code, which is understood by the computer. The compiler reads the entire program, converting it into an executable file, typically composed of binary machine instructions. Once created, this executable can be run on the target system. C++ is part of the C family of languages, which includes C itself, C++, C#, Objective-C, and Objective-C++. In contrast to a compiler, an interpreter directly processes the source code line by line, executing instructions without generating a separate executable file. Python is an interpreted language, giving C++ a head start against Python during execution. However, C++ is considerably more difficult to program in than Python.
 +
 
 +
In C++, memory is managed using variables, each of which holds a value. The <code>return</code> statement can send a value from memory back to the calling function or storage. If a function is declared with the type <code>void</code>, it does not return any value. Interestingly enough, C++ does not have a predefined string definition; you must either use <code>const char*</code> or import the "string" library.
 +
 
 +
Functions in C++ are blocks of code that perform specific tasks. They can be named, but it’s crucial to ensure that the function named <code>main</code> is the first one executed in your program, as it serves as the entry point.
 +
 
 +
The <code>#include</code> directive is used to include external files, such as libraries or header files, which contain declarations and function definitions. Be cautious not to include a file that contains the <code>main</code> function, as there can only be one <code>main</code> in a program.
 +
 
 +
In C++, header files usually have the <code>.h</code> extension, while the source code files typically have <code>.cpp</code> or <code>.cc</code> extensions. On Windows, executable files have the <code>.exe</code> extension, whereas on Unix-like systems, executables usually have no extension.
 +
 
 +
==Example==
 +
<pre>
 +
#include <iostream>
 +
 
 +
int main() {
 +
    // cout is the actual print function
 +
    // endl just flushes the buffer that
 +
    // allows C++ to say "I'm done."
 +
    std::cout << "Hello, World!" << std::endl;
 +
    return 0;
 +
}
 +
</pre>
 +
 
 +
 
 +
[[Category:Computer programming]]

Latest revision as of 16:58, 25 June 2025

Overview

C++ is a high-level programming language used for developing software. A compiler is responsible for translating the C++ code into machine code, which is understood by the computer. The compiler reads the entire program, converting it into an executable file, typically composed of binary machine instructions. Once created, this executable can be run on the target system. C++ is part of the C family of languages, which includes C itself, C++, C#, Objective-C, and Objective-C++. In contrast to a compiler, an interpreter directly processes the source code line by line, executing instructions without generating a separate executable file. Python is an interpreted language, giving C++ a head start against Python during execution. However, C++ is considerably more difficult to program in than Python.

In C++, memory is managed using variables, each of which holds a value. The return statement can send a value from memory back to the calling function or storage. If a function is declared with the type void, it does not return any value. Interestingly enough, C++ does not have a predefined string definition; you must either use const char* or import the "string" library.

Functions in C++ are blocks of code that perform specific tasks. They can be named, but it’s crucial to ensure that the function named main is the first one executed in your program, as it serves as the entry point.

The #include directive is used to include external files, such as libraries or header files, which contain declarations and function definitions. Be cautious not to include a file that contains the main function, as there can only be one main in a program.

In C++, header files usually have the .h extension, while the source code files typically have .cpp or .cc extensions. On Windows, executable files have the .exe extension, whereas on Unix-like systems, executables usually have no extension.

Example

#include <iostream>

int main() {
    // cout is the actual print function
    // endl just flushes the buffer that
    // allows C++ to say "I'm done."
    std::cout << "Hello, World!" << std::endl;
    return 0;
}