Chapter 7, Data Handling Flashcards

(41 cards)

1
Q

Data type

A

Data type are means to identify the type of data and associated operations of handling it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Fundamental data type

A

Fundamental (atomic) data type are those that are not composed of other data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the main data types of original C++?

A

C++ offers two types of data types:

  1. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do you mean by fundamental data types? How many fundamental data types does C++ provide?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The data type char is used to represent characters. Then why is it often termed as an integer type?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How are the following statements in the same set different?

A

(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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If value is an identifier of int type and is holding value 200, is the following statement correct?

Statement: char code = value;

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the advantages of floating-point numbers over integers?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How many ways can a floating-point be written into?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write 147.9205 into exponent form and 2.4901E04 into fractional form.

A

Exponent form for 147.9205: 1.479205E2 or 1.479205e2

Fractional form for 2.4901E04: 24901.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Suppose value is an identifier of int type having value 25. After the statement float chks = value;, what does the variable chks store?

A

The variable chks will store the floating-point representation of the integer value 25, which is 25.0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why is float type preferred for real quantities? When should the type double be preferred over the shorter type float?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why is float type preferred for real quantities? When should the type double be preferred over the shorter type float?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The data type double is another floating-point type. Then why is it treated as a distinct data type?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

“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.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the use of void data type?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Why does C++ have type modifiers?

A

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

18
Q

What is wrong with the following C++ statement: long float x;?

A

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.

19
Q

Using a 7-byte unit, how many different values can be represented on a computer?

A

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).

20
Q

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?

A

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)

21
Q

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?

A

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.

22
Q

What are the variations in char type ?
How are the variations of char type different from one another?

A

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.

23
Q

What are the variations in floating point type ? How are the variations of floating point type different from one another

A

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).

24
Q

Arrange the data types from smallest to largest:
Float, char, double,long double, short, int

A

char
short
int
float
long
double
long double

25
9. Distinction between 33L and 33:
33L is a long integer constant, meaning it has the type long int. 33 is an integer constant, which defaults to the type int.
26
Array
Array refer to a named list of a finite number of similar data elements
27
Structure
A structure is a collection of variables (of different data types) Referenced under one name , providing a convenient means of keeping related information together.
28
Function
A function is a named part of a program that can be invoked from other parts of the program as often needed.
29
Pointer
A pointer is a variable that hold a memory address.this address is usually to he location of another variable in memory.
30
Union
A union is a memory location that is share by two or more different variables, generally of different types at different times
31
Enumeration
An alternative method for naming integer constants is often more convenient than coust.
32
What do you understand by a class in C++? What does a structure represent in C++?
A class represents a group of similar objects.To represent classes in classes in c++, it offers a user defined data type called class.
33
What are the similarity and different between a array and a structure?
1. Contiguous Memory Allocation: Both arrays and structures allocate memory in a contiguous block, though how this memory is used differs. 2. Collections of Data: Both are used to store multiple values under a single name. Differences 1. Data Type Storage: Array: Can only hold elements of the same data type. For example, an integer array holds only integers. Structure: Can hold elements of different data types. For instance, a structure can store an integer, a character, and a float together.
34
What are the similarity and different between a class and a structure?
1. Data and Function Encapsulation: Both can store data (variables) and functions (methods) together, encapsulating data with its related behaviors. 2. Syntax and Definition: The syntax for defining a class and a structure is almost identicalDifferences 1. Default Access Specifier: Structure: Members are public by default. Class: Members are private by default. 2. Use Case Intent: Structure: Traditionally used for simpler data grouping, mainly for holding data with minimal functionality. Class: Typically used when defining more complex objects, often with encapsulated behavior and strict control over access (like private data and public methods).
35
What are the similarity and different between a class and a structure?
1. Data and Function Encapsulation: Both can store data (variables) and functions (methods) together, encapsulating data with its related behaviors. 2. Syntax and Definition: The syntax for defining a class and a structure is almost identicalDifferences 1. Default Access Specifier: Structure: Members are public by default. Class: Members are private by default. 2. Use Case Intent: Structure: Traditionally used for simpler data grouping, mainly for holding data with minimal functionality. Class: Typically used when defining more complex objects, often with encapsulated behavior and strict control over access (like private data and public methods).
36
What are the derived data type? Name the user defined data type in c++.
These are the data types that are composed of fundamental data types. These are : array, function, pointer, reference, constant,class, structure,union and enumeration
37
What is a variable? In c++, two values are associated with a symbolic variable.what are these?
A variable is a named storage location that can hold any data values.A variable has two associated values: 1 rvalue which is its data value i.e. ite contacts. 2 lvalue which is its location value i.e. memory address.
38
What is a variable? In c++, two values are associated with a symbolic variable.what are these?
A variable is a named storage location that can hold any data values.A variable has two associated values: 1 rvalue which is its data value i.e. ite contacts. 2 lvalue which is its location value i.e. memory address.
39
Why is a variable called symbolic variable?
There are two values associated with a symbolic variable: Its data value, stored at some location in memory. This is sometimes referred to as a variable's rvalue (pronounced "are-value"). Its location value; that is, the address in memory at which its data value is stored. This is sometimes referred to as a variable's lvalue (pronounced "el-value").
40
Write declarations for:
(i) A pointer to a character: char *ptr; (ii) An array of 10 integers: int arr[10]; (iii) A reference to a floating-point variable: float &ref = var; (assuming var is a previously defined float variable) (iv) A constant character: const char ch = 'A'; (v) A constant integer: const int num = 10;
41
H
(i) short integer with the value 90: short s = 90; (ii) unsigned int integer with the value 31240: unsigned int ui = 31240; (iii) An integer with the value 3000000000: long long int largeInt = 3000000000; (since 3000000000 is too large for a regular int)