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
Q

Range of integer variable

A

Determined by its size and whether is signed or not

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

Integer overflow

A

When we try to store value that is out of the range of the type, number we try to store that requres more bits.

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

Integer division

A

Doing devision with two integers, produces an integer, the fractions are droped

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

Unsigned integers

A

Integers that can only hold none negative whole numbers

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

Defining unsigned integers

A

Keyword unsigned is placed before the type

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

Unsigned integer range

A

From 0-225 in 1 byte, same as signed but signed use half of those for negative numbers

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

Integer wrap around

A

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

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

Use of unsigned integers

A

Try to avoid it, if you use it dont mix signed and unsigned numbers

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

Fixed-width integers

A

Set of integers in the stdint.h header that are guaranteed to have the same size on any architecture

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

Defining fixed-width integers

A

Std::int8_t, std::uint8_t,….std::uint64_t

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

Accesing fixed-width integers

A

By including the cstint header, where are defined inside the std namespace

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

Downsides of fixed-width integers

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

Fast type integers

A

Std::int_fast#_t provides the fastest signed integer type width of at least # bits.

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

Least type integers

A

Std::int_least#_t provides the smallest signed integer type with a width of at least # bits

39
Q

Integer best practices

A
  • 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
Q

Std::size_t

A

Unsigned integral type, used to represent the size or length of objects

41
Q

Scientific notation

A

Shorthand for writing leinghty numbers in concise manner

42
Q

Form of scientific notation

A

Significant ×10^exponent

43
Q

Numbers in scientific notation

A

Written with 1 digit before the decimal point and the rest of the digits afterwards

44
Q

Converting numbers to scientific notation

A
  • 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
Q

Significant digits

A

Digits in the significant, the more digits in the significant the more precise a number is

46
Q

Floating point type variable

A

Variable that can hold a real number (with decimals)

47
Q

Floating point data types

A

Float fvalue
Double dvalue
Long double ldvalue

48
Q

Precision of a floating point number

A

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
Q

Overriding default precision

A

By using std::setprecision() function in the iomanip header

50
Q

Rounding error

A

When precision is lost because a number can’t be stored properly

51
Q

Special cathegories of floating numbers

A
  • inf-infinity, positive and negative numbers

* NaN-not a number

52
Q

Boolean variables

A

Variables that can have only w possible values, true and false

53
Q

Declaring boolean values

A

By using keyword bool

54
Q

Initializing or assigning boolen variables

A

Assigning true or false by using the keywords true and false

55
Q

Logocal NOT operator

A

Can be used to flip a boolean value from true to false and vice versa

56
Q

Boolean values are stored as

A

Integers, they are considered integral type, true becomes 1, and false 0

57
Q

Printing boolean values

A
  • with std::cout it prints 0 and 1
  • std::boolalpha it prints true and false
  • std::noboolalpha turns it off
58
Q

Conversion from integer to boolean

A

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
Q

Inputting boolean values

A

Std::cin only accepts two inputs for boolean variables 0 and 1

60
Q

Boolean return values

A

For functions that check whether something is true or not

61
Q

If statement

A

Simplest kind of statement in c++, it allows us to execute one or more lines of code only if some condition is true

62
Q

Condition

A

Conditional ecpression is an expression that evaluates to a boolean value.

63
Q

If-else

A

Alternative form of the if statement, when we want to tell the user that the number they entered was non zero

64
Q

Chaining if statements

A

When we want to check if several things are true or false in a sequience

65
Q

Non-boolean conditionals

A

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
Q

Char data type

A

Integral type, is interpreted as ASCII characters (american standard code for information interchange, particular way te represent english characters as numbers)

67
Q

Codes0-31

A

Unprintable chars, used for formating and control printers

68
Q

Codes 32-127

A

Printable chars, represent letters, numbers and punctuation characters

69
Q

Initializing chars

A

Using character literals or with integrals

70
Q

Printing chars

A

As ASCII character with std::cout

71
Q

Ttoe cast

A

Creates a value of one type from a value of another type

72
Q

Static cast

A

Type cast used to convert between fundamental data types it doesn’t do range so an overflow is possible

73
Q

Char size, range, default size

A

Always 1 byte, signed or unsigned, number between -128 and 127 in signed and from 0- 255 unsigned

74
Q

Escape sequence

A

Characters that have special meaning starts with backslash and followed by a letter

75
Q

String

A

Collection of sequential characters when using double quotes

76
Q

Constant

A

Fixed value that may not be changed

77
Q

Tyoes of constants

A

Literal and symbolic

78
Q

Literals

A

Values inserted directly into the code, the type is assumed from the value and the format of the literal

79
Q

Literal suffixes

A
U-uninitialized
L-long
Ul-uninitialized long
Ll-long long
Ull-uninitialized long long
F-floating double
L-long double
80
Q

Declaring literals

A

With double pi{3.141559} or double avogadro{6.02e23}

81
Q

Octal decimal

A

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
Q

Hexadecimal

A

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
Q

Assigning binary literals

A

With prefix 0b, we can use quotation mark as digit seperator

84
Q

Printing decimal, octal and hexadecimal

A

Use of std::dec,oct or hex

85
Q

Printing in binary

A

Via use of type std::bitset, by defining a std::bitset variable and telling std::bitset how many bits we want to store

86
Q

Making variables constant

A

By using the const keyword before or after the variable type

87
Q

Initializing const variables

A

Must be done when defining, value can’t be changed with assigning, can be initialized from other variables

88
Q

Making function parameters const

A

Tells the person calling that the function will not change the value and ensures thet the function doesn’t change the value

89
Q

Runtime constants

A

Those whose initialization values can only be resolved at runtime

90
Q

Compile time constants

A

Those whose initializaron vues can be resolved at compile time

91
Q

Constexp

A

Ensures that the constant must be compile time constant

92
Q

Symbolic constants

A

Constant literal value

93
Q

Declaring symbolic constant

A

By using constexpr variable

94
Q

Use of symbolic constants throughout a multi file program

A

Can be declared in one central location and use then wherever we need them