Intro to C++ Part 1

Matthew·2025년 7월 29일
0

C++

목록 보기
1/1
post-thumbnail

Intro

  • Every code must be written in main() function.
    • main() function is the entry point of the C++
    • Code in main() is the first to be executed

      #include

  • Directive
  • Used to include head files.
    • Head files contains declarations of functions and objects that program can use.
  • #include <iostream> includes the iostream header, which provides objects like std::cout for outputting text to the console.

Variables

  • Hold data values.
  • Store, manipulate, display informations.
  • Initialize variable.

    Vaiable_type Variable_name = value;

  • int --> represents whole numbers.
  • float || double --> represents real numbers.
    • float --> decimal numbers // up to 7 decimal digits.
    • double --> with more precisions // up to 15 - 17 decimal digits.

      float variable_name = 99.99f;

String

  • To use string in C++, include <string> should be added on top of the code.
    2 ways to implement
    1. Adding using namespace std; after the #include <string>
    2. std::string cariable_name = "This is a string."
      #include <string>
        using namespace std; // method 1
        int main() {
      		 string s1 = "Hello."; // method 1
          std::string s2 = "Hello."; // method 2
          return 0;
       	}

Boolean

  • Only 2 possible values, true || false
    bool variable_true = true;
    bool variable_false = false;
  • When printing boolean values using cout, true --> 1 false --> 0

Char

  • Represents single character
  • keyword = char

    char variable_name = 'h';

Constants // Keyword const

  • Variables that can't be changed once it's intialized.
    const int max_value = 100;
    - max_value can't be changed.
profile
Growing Game Dev

0개의 댓글