Bits, Bytes And Data Types Flashcards

1
Q

Bit

A

Smallest unit of memory which can hold a value of 0 or 1. (On or off lightswitch)

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

Memmory addresses

A

Sequential units where the memory is organized

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

Byte

A

Group of bits that are operated on as a unit, comprised of 8 sequential bits, a byte of data is stored in each memory address

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

Data types

A

How the compiler interpretes the contents of memory in some meaningful way (ex. Integers)

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

Fundamental data types

A

Also called basic, primitive, built-in are data types built in with support of c++

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

Integers

A

Specific data types that hold positive and negative whole numbers including 0

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

Integral types

A

Includes all boolean, characters and integer types, they are stored in memory as integers

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

_t suffix

A

Type, common nomenclature applied to modern types

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

Void

A

No type, variables can’t be defined with void type

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

Use of void

A

With

  • functions that do not return a value
  • functions that do not take parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

For functions that have no paramethers

A

Use empty paramether list instead of void

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

Object sizes

A

Dependant on data types

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

Single bit

A

Can hold 2 possible values 0 or 1

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

Two bits

A

Can hold 4 possible values

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

Object with n bits

A

Can hold 2^n unique valies

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

Size of an object

A

Puts a limit on the amount of unique values it can store

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

Size of a given data type

A

Dependent on the compiler and/or the computer architecture

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

Sizeof operator

A

Unary operator that takes either a type or a variable and returns its size in bytes

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

Integer

A

Internal type that can represent positive, negative number and 0

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

C++ fundamental integer types

A

Short, int, long and long long

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

Difference between integer types

A

They have varying sizes, longer integers can hold big numbers

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

Numbers sign

A

Attribute of being positive, negative or zero

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

Defining signed integers

A

Short s, int i, long l, long long ll

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

Range

A

Set of specific values that a data type can hold

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Range of integer variable
Determined by its size and whether is signed or not
26
Integer overflow
When we try to store value that is out of the range of the type, number we try to store that requres more bits.
27
Integer division
Doing devision with two integers, produces an integer, the fractions are droped
28
Unsigned integers
Integers that can only hold none negative whole numbers
29
Defining unsigned integers
Keyword unsigned is placed before the type
30
Unsigned integer range
From 0-225 in 1 byte, same as signed but signed use half of those for negative numbers
31
Integer wrap around
Mistaken for overflow, if value is out of range, its devided by one grater than the largest number of the type, the remainder is kept
32
Use of unsigned integers
Try to avoid it, if you use it dont mix signed and unsigned numbers
33
Fixed-width integers
Set of integers in the stdint.h header that are guaranteed to have the same size on any architecture
34
Defining fixed-width integers
Std::int8_t, std::uint8_t,....std::uint64_t
35
Accesing fixed-width integers
By including the cstint header, where are defined inside the std namespace
36
Downsides of fixed-width integers
- optional, only exist if there are fundamental types matching the widths and following certain binary representation - it may be slower than a wider type on same architectures - should be avoided
37
Fast type integers
Std::int_fast#_t provides the fastest signed integer type width of at least # bits.
38
Least type integers
Std::int_least#_t provides the smallest signed integer type with a width of at least # bits
39
Integer best practices
- int should be prefered when the size of the integer doesn't matter - use std::int_fast_t if you need a variable of particular size and want to favor performance - use std::int_least_t if you need a variable of particular size and want to favor conservation
40
Std::size_t
Unsigned integral type, used to represent the size or length of objects
41
Scientific notation
Shorthand for writing leinghty numbers in concise manner
42
Form of scientific notation
Significant ×10^exponent
43
Numbers in scientific notation
Written with 1 digit before the decimal point and the rest of the digits afterwards
44
Converting numbers to scientific notation
- the exponent starts at 0 - slide the decimal so there is only 1 nonzere digit to the left of the decimal - each place you slide the decimal to the left increases, to the right decreases the exponent by 1 - trim leading and trailing 0 (only if the original number didn't had decimal point)
45
Significant digits
Digits in the significant, the more digits in the significant the more precise a number is
46
Floating point type variable
Variable that can hold a real number (with decimals)
47
Floating point data types
Float fvalue Double dvalue Long double ldvalue
48
Precision of a floating point number
Defines how many significant digits it can represent without information loss Default precision is 6 In some cases switches to scientific notation Maximum exponent digits is compiler specific
49
Overriding default precision
By using std::setprecision() function in the iomanip header
50
Rounding error
When precision is lost because a number can't be stored properly
51
Special cathegories of floating numbers
* inf-infinity, positive and negative numbers | * NaN-not a number
52
Boolean variables
Variables that can have only w possible values, true and false
53
Declaring boolean values
By using keyword bool
54
Initializing or assigning boolen variables
Assigning true or false by using the keywords true and false
55
Logocal NOT operator
Can be used to flip a boolean value from true to false and vice versa
56
Boolean values are stored as
Integers, they are considered integral type, true becomes 1, and false 0
57
Printing boolean values
* with std::cout it prints 0 and 1 * std::boolalpha it prints true and false * std::noboolalpha turns it off
58
Conversion from integer to boolean
You can't initialize using uniform initialization, but when an integer can be converted to a boolean 0 is converted to false, and any other integers to true
59
Inputting boolean values
Std::cin only accepts two inputs for boolean variables 0 and 1
60
Boolean return values
For functions that check whether something is true or not
61
If statement
Simplest kind of statement in c++, it allows us to execute one or more lines of code only if some condition is true
62
Condition
Conditional ecpression is an expression that evaluates to a boolean value.
63
If-else
Alternative form of the if statement, when we want to tell the user that the number they entered was non zero
64
Chaining if statements
When we want to check if several things are true or false in a sequience
65
Non-boolean conditionals
When the conditionis an expression that doesn't evaluate to a boolean value, the conditional expression is converted to boolean, non-zero to true, zero to false
66
Char data type
Integral type, is interpreted as ASCII characters (american standard code for information interchange, particular way te represent english characters as numbers)
67
Codes0-31
Unprintable chars, used for formating and control printers
68
Codes 32-127
Printable chars, represent letters, numbers and punctuation characters
69
Initializing chars
Using character literals or with integrals
70
Printing chars
As ASCII character with std::cout
71
Ttoe cast
Creates a value of one type from a value of another type
72
Static cast
Type cast used to convert between fundamental data types it doesn't do range so an overflow is possible
73
Char size, range, default size
Always 1 byte, signed or unsigned, number between -128 and 127 in signed and from 0- 255 unsigned
74
Escape sequence
Characters that have special meaning starts with backslash and followed by a letter
75
String
Collection of sequential characters when using double quotes
76
Constant
Fixed value that may not be changed
77
Tyoes of constants
Literal and symbolic
78
Literals
Values inserted directly into the code, the type is assumed from the value and the format of the literal
79
Literal suffixes
``` U-uninitialized L-long Ul-uninitialized long Ll-long long Ull-uninitialized long long F-floating double L-long double ```
80
Declaring literals
With double pi{3.141559} or double avogadro{6.02e23}
81
Octal decimal
Base 8 digits available 0-7 not 8 and 9, to use it prefix the literal with 0, numbers are printed in decimal so 12 octal is 10 decimal
82
Hexadecimal
Base 16 numbers included 0-9+a,b,c,d,e and f, to use it prefix with 0x,it is used for assigning binary literals
83
Assigning binary literals
With prefix 0b, we can use quotation mark as digit seperator
84
Printing decimal, octal and hexadecimal
Use of std::dec,oct or hex
85
Printing in binary
Via use of type std::bitset, by defining a std::bitset variable and telling std::bitset how many bits we want to store
86
Making variables constant
By using the const keyword before or after the variable type
87
Initializing const variables
Must be done when defining, value can't be changed with assigning, can be initialized from other variables
88
Making function parameters const
Tells the person calling that the function will not change the value and ensures thet the function doesn't change the value
89
Runtime constants
Those whose initialization values can only be resolved at runtime
90
Compile time constants
Those whose initializaron vues can be resolved at compile time
91
Constexp
Ensures that the constant must be compile time constant
92
Symbolic constants
Constant literal value
93
Declaring symbolic constant
By using constexpr variable
94
Use of symbolic constants throughout a multi file program
Can be declared in one central location and use then wherever we need them