User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







cpp:variables

This is an old revision of the document!


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!

To create a variable:

//don't worry about things that have a " * " in the comment, we'll get to those

#include iostream        //a pre-processor command *
using namespace std ;    //a declaration of the namespace used *
int main()               //the main function *
{
int var1 ;               //the declaration and naming of a variable

return 0 ;               //value return statement *
system ("pause") ;       //a system command telling the screen to pause (freeze whatever is on the screen, don't worry not your computer) *

That is your first program! It doesn't do much though.

Let's analyse the declaration and naming of the variable:

int var1 ;

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. This is a list of the most common types of variables:

bool Stores either value true or false. char Typically a single octet(one byte). This is an integer type. (one character) int The most natural size of integer for the machine. (a whole number) float A single-precision floating point value. (stores a decimal number) double A double-precision floating point value. (stores a decimal number) void Represents the absence of type. wchar_t A wide character type.

on the occasion of the current invasion of Russia in Ukraine

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

Impressum Datenschutz