Ict

Cards (56)

  • #include <iostream> - is a header file library that lets us work with input and output objects
  • using namespace std - it means that we can use names for objects and variables from the standard library
  • int main() - this is called a function.
  • cout - is an object used together with the insertion operator (<<) to output/print text
  • semicolon - every C++ statement ends with it.
  • return 0 - it ends the main function.
  • curly bracket - to actually end the main function.
  • \n - used to insert a new line
  • endl - another way to insert a new line
  • The newline character (\n) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.
  • \t - it creates a horizontal tab
  • \\ - it inserts a backslash character (\)
  • \" - it inserts a double quote character
  • Comments - it can be used to explain C++ code, and to make it more readable. It can also be used to prevent execution when testing alternative code. It can be singled-lined or multi-lined.
  • // - single-line comments starts with it
  • Multi-line comments start with /* and ends with */.
  • int - stores integers (whole numbers), without decimals, such as 123 or -123
  • double - stores floating point numbers, with decimals, such as 19.99 or -19.99
  • char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
  • string - stores text, such as "Hello World". String values are surrounded by double quotes
  • bool - stores values with two states: true or false
  • These unique names are called identifiers. It can be short names (like x and y) or more descriptive names (age, sum, totalVolume).
  • cin - is a predefined variable that reads data from the keyboard with the extraction operator (>>).
  • operators - are used to perform operations on variables and values.
  • + - adds together two values
  • - - subtracts one value from another
  • * - multiplies two values
  • / - divides one value by another
  • % - returns the division remainder
  • ++ - increases the value of a variable by 1
  • -- - decreases the value of a variable by 1
  • Comparison operators - are used to compare two values (or variables).
  • Logical operators - are used to determine the logic between variables or values
  • && - returns true if both statements are true
  • || - returns true if one of the statements is true
  • ! - reverse the result, returns false if the result is true
  • The + operator can be used between strings to add them together to make a new string. This is called concatenation
  • A string in C++ is actually an object, which contain functions that can perform certain operations on strings. For example, you can also concatenate strings with the append() function
  • getline() function to read a line of text.
  • Use if to specify a block of code to be executed, if a specified condition is true