OOPortal
RationalDB Database Design
prev prev
  Course navigation
    C++ const and type safety
The use of const is highly desirable because it protects a variable from inadvertent change and documents the use of the value. Furthermore, the compiler is at liberty to optimize code connected to constants, for example storing them in read-only high-speed memory.
Type-safety is an important property of C++. Compilers are able to perform type checking statically and consequently find bugs that would be difficult to discover at runtime. The narrower the type, the more safety and, frequently, the more efficiency. Integer arithmetic is usually more accurate and faster than floating-point arithmetic.
A char or a short takes less space than an int or a long.
  Course navigation