Belajar C++ [Dasar] - 01 - Apa itu C++

3 min read 1 hour ago
Published on Oct 07, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

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:

  1. Choose a Compiler:

    • Popular options include:
      • GCC (GNU Compiler Collection)
      • Clang
      • Microsoft Visual C++
  2. 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
  3. Verify Installation:

    • Open your terminal (Command Prompt or Terminal) and type:
      g++ --version
      
    • This command checks if the GCC compiler is installed correctly.

Step 3: Writing Your First C++ Program

Now that your environment is set up, let's write a simple C++ program:

  1. Open your IDE or text editor.

  2. Create a new file named hello.cpp.

  3. Write the following code in the file:

    #include <iostream>
    
    int main() {
        std::cout << "Hello, World!" << std::endl;
        return 0;
    }
    
  4. Save the file.

  5. 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 integers
      • float for floating-point numbers
      • char for characters
      • string for strings of text
  • Control Structures:

    • Use if, else, and switch statements for conditional logic.
    • Use loops (for, while) for repeating tasks.
  • 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++.