Chapter 7, Data Handling Flashcards
(41 cards)
Data type
Data type are means to identify the type of data and associated operations of handling it
Fundamental data type
Fundamental (atomic) data type are those that are not composed of other data type.
What are the main data types of original C++?
C++ offers two types of data types:
- Fundamental data types: These are five fundamental data types: char, int, float, double and void. 2. Derived data types: These are derived data types: array, function, pointer, reference, constant, class, structure,union and enumeration.
What do you mean by fundamental data types? How many fundamental data types does C++ provide?
Fundamental data types are the data types that are not composed of any other data type.
C++ provides these five fundamental data types: char, int, float, double and void.
The data type char is used to represent characters. Then why is it often termed as an integer type?
The memory implementation of char data type is in terms s of the number code. Therefore, it is said t Ito be another integer data type.
How are the following statements in the same set different?
(i) The first statement stores the ASCII value of character ‘k’, whereas the second statement stores a character ‘k’.
(ii) The first statement stores the ASCII value of character ‘k’, whereas the second statement stores numeric value 75.
(iii) No difference. In constant declaration when data type is skipped, by default it is int.
If value is an identifier of int type and is holding value 200, is the following statement correct?
Statement: char code = value;
This statement is syntactically correct, but there might be a loss of data. Since char can only hold values in the range -128 to 127 (for signed char) or 0 to 255 (for unsigned char), assigning value (200) to code might result in a truncated or overflowed value, depending on the implementation of char.
What are the advantages of floating-point numbers over integers?
Floating-point numbers have two advantages over integers. First, they can represent values between the integers. Second, they can represent a much greater range of values.
How many ways can a floating-point be written into?
A floating-point number can typically be written in two main ways:
Standard (fixed-point) notation, e.g., 123.45
Exponential (scientific) notation, e.g., 1.2345E2 or 1.2345e2
Write 147.9205 into exponent form and 2.4901E04 into fractional form.
Exponent form for 147.9205: 1.479205E2 or 1.479205e2
Fractional form for 2.4901E04: 24901.0
Suppose value is an identifier of int type having value 25. After the statement float chks = value;, what does the variable chks store?
The variable chks will store the floating-point representation of the integer value 25, which is 25.0.
Why is float type preferred for real quantities? When should the type double be preferred over the shorter type float?
The float type is preferred for real quantities when memory usage is a concern, as it uses less memory than double. However, double is preferred when higher precision is needed, as it has a larger range and more precision due to double the number of bits compared to float.
Why is float type preferred for real quantities? When should the type double be preferred over the shorter type float?
The float type is preferred for real quantities when memory usage is a concern, as it uses less memory than double. However, double is preferred when higher precision is needed, as it has a larger range and more precision due to double the number of bits compared to float.
The data type double is another floating-point type. Then why is it treated as a distinct data type?
double is treated as a distinct data type because it has a greater precision and range than float. It typically uses twice the memory of float (64 bits compared to 32 bits), allowing for more precise and larger magnitude numbers.
“The floating-point numbers should always be stored in the largest type long double because it saves us from the headache of consulting the minimal ranges these data types support.” Comment upon this statement.
This statement is not entirely correct. While long double provides more precision and range, it also consumes more memory, which may be unnecessary for certain applications. Using long double for every floating-point number could lead to inefficient memory use. The choice of data type should be based on the required precision and memory constraints of the application.
What is the use of void data type?
The void type specifies an empty set of values. It is used as the return type for functions that do not return a value. No object of type void may be declared.
Why does C++ have type modifiers?
You use a modifier to alter the meaning of the base type to fit various situations more precisely.
The list of modifiers is given below :
signed
unsigned
long
short
What is wrong with the following C++ statement: long float x;?
The statement long float x; is incorrect because float does not have a long modifier. The correct data types are float, double, and long double. double can be used for higher precision, or long double for even greater precision than float.
Using a 7-byte unit, how many different values can be represented on a computer?
With 7 bytes (56 bits), the number of different values that can be represented is , which is 72,057,594,037,927,936 (approximately 72 quadrillion).
On a machine, short integer is 2 bytes long. What can be the possible size for int integer, short integer, and long integer on the same machine, keeping in mind C++ standard?
According to the C++ standard, the sizes may vary, but typically:
short integer: 2 bytes
int integer: 2 or 4 bytes (most commonly 4 bytes)
long integer: 4 or 8 bytes (most commonly 4 bytes, but can be 8 bytes on some systems)
If short integer on a machine is 4 bytes long, what will be the size of unsigned short and signed short on the same machine?
If a short integer is 4 bytes, both unsigned short and signed short will also be 4 bytes. The unsigned and signed modifiers affect the range of values, not the storage size.
What are the variations in char type ?
How are the variations of char type different from one another?
Variations in char type:
The char type in C++ can have the following variations:
Signed char: Can hold negative values.
Unsigned char: Only holds non-negative values.
Plain char: The behavior (signed or unsigned) is implementation-dependent, though it’s usually signed.
Differences:
Signed char ranges from -128 to 127 (in most systems).
Unsigned char ranges from 0 to 255.
Plain char behaves like either signed char or unsigned char depending on the compiler and system.
What are the variations in floating point type ? How are the variations of floating point type different from one another
Variations in floating-point types:
C++ provides three main floating-point types:
float: Single-precision floating-point.
double: Double-precision floating-point.
long double: Extended-precision floating-point.
Differences:
float has lower precision and takes up less memory (typically 4 bytes).
double provides greater precision than float and typically takes up 8 bytes.
long double offers even more precision and size, though its size can vary (often 10, 12, or 16 bytes).
Arrange the data types from smallest to largest:
Float, char, double,long double, short, int
char
short
int
float
long
double
long double