J

@jogomu

pointers and shared_ptr

C++
4 years ago
#include <iostream> #include <memory> int main() { int a; // this holds an integer on the stack a = 5; int *p; // this holds the address (location in memory) of some other integer p = &a; // the & takes the address of a and = assignes it to p printf("%d\n", a); // we can print a printf("%d\n", *p); // or we can use * to get from the pointer back to what it points to

optionally sorted linked list

C++
4 years ago
#include <cstdio> #include <memory> #include <functional> template <typename T> struct Node { Node(const T &t) { val = t; } ~Node() { printf("removing Node\n"); } T val;

references2 - cpp

C++
5 years ago
#include <iostream> #include <cxxabi.h> int main() { int32_t a = 47; auto p = &a; auto p2 = &p; auto p3 = &p2; ***p3 = 48; // make sure you understand why this is the same as "a"

references - python

Python
5 years ago
# In python, variables refer to objects... # Everything is an object, but only some objects # can be modified. a=9 # a refers to the "9" object, but nine is always nine b=a # b now refers to the same object as a, which is "9" b=7 # now b refers to the "7" object and no longer to "9" # lists can be modified:

references - cpp

C++
5 years ago
#include <iostream> #include <cstdint> int main() { int32_t a = 47; printf("a is %d\n",a); // prints the value of a // (int32_t *) is a "pointer" type... it holds the location of an int32_t // & is how you get the location of something... so &a is the location of a in memory

std::chrono

C++
5 years ago
#include <iostream> #include <chrono> #include <cxxabi.h> int main() { auto now = std::chrono::system_clock::now(); // What type is "now" since it was automatically determined from the rhs? // (rhs = right hand side.. of the assignment)

python quotes

Python
5 years ago
a=5000000000 # python would automatically decide that this needs more than 32 bits print(f'Hello world! The number is {a}') b="A string in double quotes" c="A string in single quotes" d="A string with a single quote (') in it" e='A string with a double quote (") in it' f='A string with both single (\') and double quotes (")' print(b)

basic types

C++
5 years ago
#include <iostream> #include <cstdint> // int32_t etc int main() { // we discussed integer types // remember that an unsigned integer can store 0 to (2^bits)-1 int a; // different platforms will have different standard # bits for int unsigned int b; // non-negative only int32_t c; // this will be 32 bits for sure

timed random - python

Python
5 years ago
import time # time.time() import random # random.random() d=[] start=time.time() for i in range(1000000): d.append( random.random() ) stop=time.time() print(f"operation took {stop-start} seconds") print(d[0:3])

timed random - cpp

C++
5 years ago
#include <cstdlib> // for drand48() #include <cstdio> // for printf() #include <sys/time.h> // for gettimeofday() // note: we probably don't want gettimeofday() but keeping the concepts simple // for now, cf https://stackoverflow.com/questions/10905892/equivalent-of-gettimeday-for-windows int main() { struct timeval start, stop;