Computational Physics wiki (UCAM only) / C++ resources /

Simple C++ examples

What you want What it is called Examples
loops do .. while
loopswhile (has never-ending loop)
input from usercin
definition #define
pass by reference&
shared definitions#include (header file) and rand.h
conditional if / else
? (ternary operator)
switch / case
random random() (random integer between 0 and 231
srandom() (initialize/seed the generator) (seeds using time) (user-supplied seed)
input from command lineargv, sscanf
convert string to int or long intsscanf
integer arithmetic unsigned int
power (xy)pow(x,y)
bit-shift (1<<i)
Examine memory bit by bit& (bit mask)
input from fileifstream, open, getline, close
remember variablesstatic
arraysfloat vector[3]
char phone[11]
dynamically allocate memory for vectors/ arrays/ matricesint *a, new, delete
dynamically allocate double arrays/matricesdouble *a, new, delete
useful warnings when compilingmakefile Makefile
Classes class
convert between typescast, reinterpret_cast, static_cast (not yet finished)
[an error occurred while processing this directive]

David MacKay / Computational Physics wiki (UCAM only) / C++ resources /

David MacKay / python resources /