Cloudbook: C

  1. Home
  2. Variables
  3. Modeling
  4. § 2 exercise →
Type

A type is a collection of values and operations defined on those values. A variable is a memory location capable of storing and retrieving a value of a specific type. A representation is chosen that associates the distinct states of the memory with values. The hardware of the CPU coordinates with the representation so that the operations can be applied efficiently in that representation.

The smallest unit of allocatable storage is a byte, and a byte is a collection of 8 bits. Each bit is the smallest possible representation of state as either zero or one. Consequentially 28 or 256 distinct states are available in a byte to represent up to 256 different values. If k bytes are used, the bytes can be used in all combinations of different states individually, for 256k different states in combination; so that 256k difference values can be represented.

To storage and retrieve variable values, each byte is given an address, and the computer can store and fetch the value at the address. If a location requires multiple bytes, the address is that of the first byte of several consecutive bytes by address. The variable's type implies the number of bytes in the location. Operations on the variable will understand how many bytes of memory will be involved because the variable has a type.

Therefore variable has two values associated with it: the first is the value that is stored in the location, called the variable's rvalue; the second is the address of the location, called the variable's lvalue.

In the expression: i = j, j is evaluated for its rvalue, since it is the value stored in j that will be assigned to i; and i is evaluated for its lvalue, since what is needed is the address of the location wherein the value will be stored.