1/23
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
data type definition
collection of data objects and a set of predefined operations on those objects;
stored value (instructions and data) in memory are untyped, as hardware on most machines makes no attempt to keep track of which interpretations correspond to which locations in memory
type checking
activity of ensuring that the operands of an operator are of compatible types
type error
the application of an operator to an operand of an inappropriate type
strongly typed programming language
type errors are always detected
type system of a programming language
Defines how a type is associated with each expression in the language and includes its rules for type equivalence and type compatibility
descriptor, and difference between descriptor of static and dynamic variables
collection of the attributes of a variable that are used for type checking and performing allocation and deallocation operations
structured vs scalar data types
scalar data types are those that include a single value, like int, bool, double, etc.
structured data types are those which include composite values, like arrays.
primitive data types
data types that cannot be represented in terms of other data types
what does sizezof operator do in C/C++
it gives the size of the variable or data type in bytes
integer primitive type
what are they in non-decreasing order?
what is the fixed size of byte? short? int? long? in java*
signed vs unsigned integers, qu’est-ce que c’est?
can an integer be declared as unsigned
char, short, int, long, long long
1,2,4,8
one of the bits in the integer is represented as a sign bit
yes
what is two’s complement rule?
hardware representation of signed integers in binary: take the COMPLEMENT of the binary rep of the number, and then add one.
floating point primitive type
what is the c++ data types of this, in non-decreasing order of size
defined in terms of ____ and ____.
what is the formula to convert a 32-bit binary string into a decimal number?
are they always like hardware?
float, double, long double
precision and range
value = sign x mantissa x 2^{exp}, where sign is a plus or minus, the 2^{exp} has exp = 8 bits after sign - 127; manitssa is the rest of the digits where you concat a “1.” at start, and then for each binary digit starting with the leftmost one (after exponent), you multiply that digit by (0.5), (0.25), (0.125), and onwards.
usually, but not always.
boolean primitive type
is it implemented as bits or bytes?
what are allowable ops?
can be implemented as bits, but usually bytes
the logical !, ||, &&, and relational operations
char primitive type
what are they stored as? (braindead) what is the most commonly used one?
size of char in C++ vs java
what is the c++ data type for unicode characters
numbers (numeric codings); ASCII, or Extended ASCII (128, 256 chars respectively)
1 byte and 2 bytes
wchar_t
character string data type
is this primitive in C and C++?
is it primitive in Python?
how is this different than Strings in java?
which 3 kinds of strings are of static length?
which languages can implemented strings as limited dynamic and how?
what does the compile time descriptor look like for static strings
what does the run time descriptor look like for limited dynamic strings?
no
ja
it is not. Java string class is just character strings.
java’s string class, c++ standard string, and python string
C and C++ with the string-end being a unique character
static string ; length ; address
limited dynamic string; max length; curr length; address
enums
what are rules for constant appearance in declaration
can you set integer to enum constant? int x = Mon;
can you set enum constant to any datatype? how do you do it legally?
what is the only way to do incrementation / decrementation?
enums vs scoped enums in terms of what you’re allowed to do with adding consts and assigning ints
it can only appear once
ja
no. only way to do it legally: const = (enumName) 4; (4 is an arbitrary int)
const = (enumName) (const + 1);
enums don’t care about adding consts, they treat it as integers, but they don’t let you IMPLICITLY set consts to random nums but you can do so EXPLICITLY. scoped enums don’t let you add consts, and they work the same for setting consts to random ints.
pointers
what are the two possible values?
what is size?
what is indirect accessing?
what are dangling pointers? remember code example.
what is a lost heap-dynamic variable? what is another name for that variable?
pointer arithmetic formula?
what does doing ptr++ or ++ptr , ptr—, —ptr do?
what happens when you subtract two pointers?
can you add, multiply, or divide pointers?
can you do math on void*?
consider some index i inside an array arr . explain relationship with pointer.
what are void pointers and their rules?
is this legal or not, and why: int* p = malloc(sizeof(int)); ?
any memory address or NULL
8 bytes
accessing a variable in two steps, first by using a pointer that gives the location of var in memory
pointer that points to heap dynamic variable which has been deallocated.
it’s a dynamic variable that is no longer being pointed to, meaning its inaccessible and GARBAGE.
new address = old_address + n*(sizeof(type))
move pointer to next element in memory or prev
only allowed when both point to same array, and it gives the number of elements between the two pointers
no. never.
no.
arr[i] = *(arr + i) = *(i + arr) + i[arr]
they can point to literally any type of variable. however, you cannot deference them or do ANY kind of pointer arithmetic. you must cast them into a normal pointer to deference and shit.
ts NOT legal in C++, but legal in C. since malloc memory is of void, you gotta cast the RHS to (int*)
can you have a reference of a reference? can you have a pointer to a reference?
no, no.
lvalue vs rvalue references
lvalue
declared by placing a & a type
synonym for the object it references
cannot set equal to literal made strings “hello” or substrings
rvalue
declared by placing && a type
same as lvalue, but can set to literal temp strings and substrings like string && x = “hello”;
references are references to ____ instead of being ______.
objects, addresses.
pointers widen what?
range of references to memory cells that can be accessed by a variable
what data types can be used as indices for arrays
char, bool, short, int, long
what is unique about java arrays (& variables declared as arrays in Java)
they are objects. such variables are references to the array objects and have memory allocated to them. we always know how many items are in them.