new
in Java, what
happens?
main.cpp
, review that code
echo %ErrorLevel%
echo $?
endl
(that is, your output is a series of
lines), be sure the last output line is terminated with an endl
cout << something-or-other << endl;
hello, <name>
string name
;
if name == "Walz"
print "lord" instead
.equals
By definition: sizeof char == 1 1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
int count = 0; int count {0}; // alternative form int count = 0.5; // count = 0, but no error int count {0.5}; // ILLEGAL - get error, but this is good!
auto b = true; // bool auto ch = 'x'; // char auto count = 0; // int auto d = 1.2; // double
const int a = get_integer(); // legal (assuming get_integer reads num) constexpr int a = get_integer(); // NOT legal
constexpr int MAX_LENGTH = 100; constexpr int SECONDS_PER_DAY = 60 * 60 * 24;
read while not eof process read
for(auto x : fibs) cout << x << endl;
return_type name(type p1, type p2, ...) { ... body ... }
void
function
x
in sqrt(x)
p1
and p2
above
int
or double
and classes like string
void
: indicates no return statement
void p(int x);
, the code y =
p(3);
would be illegal since you can't create or
store a void
value
return
statement, the
return result is undefined - that is, it could be anything
float f(float x) { return x * x + 3 * x - 5; } ... f(5); // legal, even if not useful!This is because there are several library functions that return results that can be routinely ignored such as functions which read input and return the number of items read.
int distance(int a, int b) { return a > b ? a - b : b - a; } double distance(double a, double b) { return a > b ? a - b : b - a; } double distance(double x1, double y1, double x2, double y2) { double x_delta = x2 - x1, y_delta = y2 - y1; return sqrt(x_delta * x_delta + y_delta * y_delta); }
int f(int a); double f(int a); // illegal!
string operator+(string a, string b) { // REALLY bad idea!! string result = "xx"; result[0] = a[0]; result[1] = b[1]; return result; }
.equals
; the libraries
overload operator=
for two strings
int operator+(int a, int b); // ILLEGAL!
double f(int x, double y = 0.0, double z = 0.0) { return x + 2 * y + 3 * z; }Then the following are all legal calls: f(3), f(4, 5), f(5, 5, 6); for f(4, 5), z is 0 - drop right to left
void doit(int x, double nums[]) { x *= 2; x[nums] = x * x; } double stuff[100]; int a = 5; doit(a, stuff);then a will still be 5 after the call, but stuff[10] will be 25.