Main menu

Pages

C++ variables - Learn CPP, Variable: It is the reservation of a set of data in the random computer memory (Random Access Memory), i.e. (RAM); To store values in it so that we can retrieve it at another time, where variable values are placed in those reserved bits, they can be retrieved at any time, every byte is accessed via an address, and this memory loses all its data when the current is cut off. In order to understand the variables well, it is recommended to understand the way the computer's RAM works.

RAM is a temporary memory used to store data in computers, and it is a chip that contains a number of transistors and capacitors, which are estimated at millions, as one transistor and a capacitor form a unit of memory estimated by bits. This bit is either the value zero (0) or the value one (1), where eight bits make up one byte, and each byte of this memory is represented by an address (these addresses are dealt with in the hexadecimal system), which can be accessed and changed in its content, which we understand that memory They are sequential addresses, each address has a variable value. They are also called temporary because once the power is cut off, all data and information stored on them are lost.


C++ variables - Learn CPP


How to declare variables


In the C language, there are a lot of constants and variables, including variables with integers, others with real numbers, and others with letters, and we always declare them before using them, whether as variables or constants, that is, we reserve the place first and then put a value.


The way to declare variables is to mention the type of the variable and then its name so that they are separated by a space, and the sentence must be ended with a semicolon.


An example of defining a literal variable:; Char x


And if we want to give it a direct value, we put the value after the variable name.


Rules for naming variables


  • It must not contain variables.
  • It should not start with a number.
  • Some compilers accept no more than 32 characters and neglect the rest.
  • When using a variable name consisting of two letters, we put a dash between them.
  • Uppercase letters differ from lowercase letters, for example, A differs from a.
  • The variable does not contain special signs (+,*,$,%).
  • The variable must not contain spaces.
  • It must not contain any of the reserved words.


reserved words


  • auto.
  • const.
  • break.
  • double.
  • int.
  • float.
  • short.
  • for.
  • goto.
  • return.
  • while.
  • Long.
  • do.
  • case.
  • continue.
  • else.
  • register.
  • unsigned.
  • struct.
  • static.
  • if.
  • union.
  • enum.
  • void.
  • default.
  • sizeof.
  • switch.
  • extern.
  • typedef.