Belajar C++ [Dasar] - 01 - Apa itu C++
Table of Contents
Introduction
This tutorial introduces the basics of C++, a powerful programming language widely used for system/software development, game programming, and performance-critical applications. Whether you're a complete beginner or looking to refresh your knowledge, this guide will provide you with a clear understanding of what C++ is and its significance in the programming world.
Step 1: Understanding What C++ Is
- C++ is an extension of the C programming language, adding object-oriented features.
- It combines both high-level and low-level programming capabilities, making it versatile for various applications.
- Commonly used for:
- Developing operating systems
- Game development
- Real-time simulations
- Applications requiring high-performance
Step 2: Setting Up Your C++ Development Environment
To start programming in C++, you need to set up your development environment:
-
Choose a Compiler:
- Popular options include:
- GCC (GNU Compiler Collection)
- Clang
- Microsoft Visual C++
- Popular options include:
-
Install an IDE or Text Editor:
- Recommended IDEs:
- Code::Blocks
- Visual Studio
- Eclipse
- You can also use text editors like:
- Visual Studio Code
- Sublime Text
- Recommended IDEs:
-
Verify Installation:
- Open your terminal (Command Prompt or Terminal) and type:
g++ --version
- This command checks if the GCC compiler is installed correctly.
- Open your terminal (Command Prompt or Terminal) and type:
Step 3: Writing Your First C++ Program
Now that your environment is set up, let's write a simple C++ program:
-
Open your IDE or text editor.
-
Create a new file named
hello.cpp
. -
Write the following code in the file:
#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }
-
Save the file.
-
Compile and Run the Program:
- Open your terminal and navigate to the directory where your file is saved.
- Compile the code by typing:
g++ hello.cpp -o hello
- Run the program by typing:
./hello
Step 4: Exploring Basic C++ Concepts
Familiarize yourself with the following fundamental concepts in C++:
-
Variables and Data Types:
- Common data types include:
int
for integersfloat
for floating-point numberschar
for charactersstring
for strings of text
- Common data types include:
-
Control Structures:
- Use
if
,else
, andswitch
statements for conditional logic. - Use loops (
for
,while
) for repeating tasks.
- Use
-
Functions:
- Define reusable blocks of code with functions.
- Example:
int add(int a, int b) { return a + b; }
Conclusion
C++ is a versatile programming language that serves as a foundation for many other languages and applications. By following this guide, you have set up your development environment, written your first program, and learned about essential concepts.
Next Steps:
- Explore more complex topics such as classes and objects in C++.
- Join online communities like Discord or Telegram for support and resources.
- Practice coding regularly to solidify your understanding and skills in C++.