:pen: Address (Memory location)
The memory address with which a variable is associated.
:black_small_square: Also called l-value because that is what is required when a variable appears in the LHS of an assignment.
A variable (identified by its name) may have different addresses at different places in a program
A variable may have different addresses at different times during execution
Aliasing
:black_small_square: Two variables (say x, y) may refer to the same storage location. x is called an alias of y and vice versa.
:black_small_square: Aliases are meant to save storage by allowing the data at a particular location to be viewed/used differently at different times.
:black_small_square: Different languages provide different ways to create aliases(FORTAN EQUIVALANCE,Pascal, Ada Variant record structures,Pointers,Reference variables,C and C++ unions)
:black_small_square: Some of the original justifications for aliases are no longer valid(Ex : memory reuse in FORTAN replace them with dynamic allocations)
Problems in using Aliases
:black_small_square:Difficult to read and understand programs.
:black_small_square:Program verification more difficult.
Unions in C
:black_small_square: In C programming, a union is a user-defined data type that allows storing different types of data in the same memory location.
:black_small_square: Unlike structures, where each member has its own memory space, a union shares a single memory block among all its members.
:black_small_square: The memory allocated for a union is equal to the size of its largest member.
:black_small_square: This means that modifying the value of one member can affect the values of other members. Only one member of the union can be accessed at a time, and it is the responsibility of the programmer to keep track of which member is valid or meaningful to access.
:black_small_square: Unions are primarily used in situations where memory efficiency is a concern, and the programmer wants to store different types of data in the same memory block.
:black_small_square: However, it is crucial to handle unions with caution to avoid unintended consequences and ensure that the correct member is accessed and interpreted.