User Tools

Site Tools


cpp:variables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cpp:variables [2014/02/07 23:55]
173.69.2.138
cpp:variables [2024/02/16 00:48] (current)
Line 1: Line 1:
-Variables-+**Variables**
    
 Variables are the means of storing data in a program. Say you want to make a calculator, you need to use variables. Say you want to make a program that takes in a word and then modifies it, you need to use variables. Variables can be created and "destroyed"(deconstructing comes later on so don't get your hopes up). The value or information that they store can be changed and in some cases, that you make it so, cannot be. Except for the syntax of the language, //you// are in control! Variables are the means of storing data in a program. Say you want to make a calculator, you need to use variables. Say you want to make a program that takes in a word and then modifies it, you need to use variables. Variables can be created and "destroyed"(deconstructing comes later on so don't get your hopes up). The value or information that they store can be changed and in some cases, that you make it so, cannot be. Except for the syntax of the language, //you// are in control!
  
 To create a variable: To create a variable:
-<code>+<code cpp>
 //don't worry about things that have a " * " in the comment, we'll get to those //don't worry about things that have a " * " in the comment, we'll get to those
  
Line 24: Line 24:
 The syntax of naming a variable is the following [varaible type] [varaible name] The syntax of naming a variable is the following [varaible type] [varaible name]
  
-The name of the variable can be whatever you want, but it is good programming practice to make it a descriptive title corresponding to what the variable stores.+The name of the variable can be whatever you want, except a number, but it is good programming practice to make it a descriptive title corresponding to what the variable stores.
  
 This is a list of the most common types of variables: This is a list of the most common types of variables:
  
-<code>+<code cpp>
 bool Stores either value true or false. bool Stores either value true or false.
 char Typically a single octet(one byte). This is an integer type. (one character) char Typically a single octet(one byte). This is an integer type. (one character)
Line 37: Line 37:
 wchar_t A wide character type. wchar_t A wide character type.
 </code> </code>
 +
 +Now you have allocated memory for the varaible. That is just reserving space for it. You haven't set the value of it yet. When you do, then the space is filled.
 +
 +Our variable was an "int" or, in Enlish, an integer. Let's make the variable equal to a number.
 +<code cpp>
 +int var1 ;
 +var1 = 5 ;
 +</code>
 +The variable var1 now equals 5. You could also set the value when you declare it like such:
 +<code>
 +int var1 = 5 ;
 +</code>
 +
 +Variables can even be equal to each other!
 +<code cpp>
 +int var1 = 6 ;
 +int var2 ;    //another integer variable named "var2"
 +var2 = var1 ; //the value of var2 is now the same as the value of var1 
 +</code>
 +
 +<fc #FF0000>**Useful Tip**</fc>
 +When making a variable equal to something, you must use this syntax:
 +[the varaible that you want to change] = [the number or existing varaible] ;

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
cpp/variables.1391813738.txt · Last modified: 2024/02/16 00:47 (external edit)

Impressum Datenschutz