TYPES WEEK 2 Flashcards
(23 cards)
Description: Programming languages that use a type system to interpret bit streams in memory.
Title: Typed Programming Languages
Description: A typed programming language that uses types to define how to store values in memory and which operations are allowed on those values.
Title: C Language
Description: Rules that define how to store values in memory and which operations are admissible on those values.
Title: Types
Description: The four most common types in C for performing arithmetic calculations: char, int, float, and double.
Title: Arithmetic Types in C
Description: Occupies one byte and can store a small integer value, a single character, or a single symbol.
Title: Char Type
Description: Occupies one word and can store an integer value. In a 32-bit environment, an int occupies 4 bytes.
Title: Int Type
Description: Typically occupies 4 bytes and can store a single-precision, floating-point number.
Title: Float Type
Description: Typically occupies 8 bytes and can store a double-precision, floating-point number.
Title: Double Type
Description: Adjust the size of the int type. Three specifiers: short, long, long long.
Title: Size Specifiers for Int Type
Description: Keyword used to qualify a type as holding a constant value. A const-qualified type is unmodifiable.
Title: Const Qualifier
Description: Char and int types are stored in equivalent binary form.
Title: Integral Types
Description: Float and double types are used to represent floating-point data.
Title: Floating-Point Types
Description: Hardware manufacturers represent integral and floating-point data differently.
Title: Representing Values
Description: C stores characters and symbols in char types. The host platform provides a collating sequence for associating each character and symbol with a unique integer value.
Title: Characters and Symbols
Description: ASCII and EBCDIC are two popular collating sequences that are not compatible with each other. The Unicode standard provides a much more comprehensive collating system that is compatible with ASCII.
Title: Collating Sequences
Description: Provides information on how to convert between decimal and binary representation.
Title: Appendix on Data Conversions
Definition: There are three schemes for storing negative integers - 2’s complement notation (most popular), 1’s complement notation, and sign magnitude notation. All three represent non-negative values identically. To obtain the 2’s complement of an integer, flip the bits and add one.
Term: Negative Values (Optional)
Definition: Floating-point types store tiny as well as huge values by decomposing the values into three distinct components - a sign, an exponent, and a significand. The most popular model is the IEEE (Institute of Electrical and Electronics Engineers) Standard 754 for Binary and Floating-Point Arithmetic. Under IEEE 754, a float has 32 bits, consisting of one sign bit, an 8-bit exponent, and a 23-bit significand, while a double occupies 64 bits, has one sign bit, an 11-bit exponent, and a 52-bit significand.
Term: Floating-Point Data
Definition: The number of bytes allocated for a type determines the range of values that that type can store. For integral types, the ranges of values for some types depend on the execution environment. char (8 bits) can store values from -128 to 127 or 0 to 255, short (>= 16 bits) can store values from -32,768 to 32,767, int (2 or 4 bytes) can store values from -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647, long (>= 32 bits) can store values from -2,147,483,648 to 2,147,483,647, and long long (>= 64 bits) can store values from -9,233,372,036,854,775,808 to 9,233,372,036,854,775,807. For floating-point types, the limits on a float and double depend on the execution environment.
Term: Value Ranges
Variable Declarations
We store program data in variables
A declaration associates a program variable with a type
The type identifies the properties of the variable
In C, a declaration takes the form: [const] type identifier [= initial value];
It is good practice to declare all variables at the beginning of the function and group related variables together
Variable Declarations
We store program data in variables
A declaration associates a program variable with a type
The type identifies the properties of the variable
In C, a declaration takes the form: [const] type identifier [= initial value];
It is good practice to declare all variables at the beginning of the function and group related variables together
Multiple Declarations
Group variables of the same type in a single declaration
Separate the identifiers with commas
Multiple Declarations
Group variables of the same type in a single declaration
Separate the identifiers with commas
Naming Conventions
Select identifier names that follow these naming conventions:
Starts with a letter or an underscore (_)
Contains any combination of letters, digits, and underscores
Less than 32 characters (varies by compiler)
Not a reserved word in C
Use good variable naming techniques
Avoid using reserved words
Naming Conventions
Select identifier names that follow these naming conventions:
Starts with a letter or an underscore (_)
Contains any combination of letters, digits, and underscores
Less than 32 characters (varies by compiler)
Not a reserved word in C
Use good variable naming techniques
Avoid using reserved words
Reserved Words
Certain words are reserved in C and C++
These words should be avoided as variable identifiers
To ensure upward compatibility with C++, avoid certain C++ reserved words.
Reserved Words
Certain words are reserved in C and C++
These words should be avoided as variable identifiers
To ensure upward compatibility with C++, avoid certain C++ reserved words.