Week 5

From CDOT Wiki
Revision as of 14:14, 10 June 2010 by Jaburton1 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Creating pointers to functions

type foo(type 1, type2, type3, etc);

type (*P)(type1, type2, type3, etc);

P is a pointer variable to a function foo.

Assigning a function to a pointer variable:

P = foo;

In C (or C++), x = (*P)(type1, type2, type3);

In C++, x = P(y, z, x);

In C, everything upcasts. (so if you have an expression, it will upcast all the variables to the largest type).

New Concepts

Page 36 - review it carefully.

difference between a structure and a class in C++ structure is public by default, classes are private by default.

in c - instantiate a structure: struct student s; c++ - student s;

union - places all the variables in the same place in memory. enum weekdays(sun, mon, tue, wed, thu, fri, sat) - will create 7 constant ints starting from 0

typedef int age - adds the name "age" as an integer to the C library. so now u can say "age a = 34;" - same as saying int a = 34

c = 20 || 50

c = true because both 20 and 50 are not 0 which is false.

in the ? : operator both values must be same data type. ignore page 37

bitwise operators?? AC 1010 1100 = A 4E 0100 1110 = B

A && B = 0000 0001 A & B = 0000 1100 A | B = 1110 1110 ! A = 0000 0000 ~A = 0101 0011 A^B = 1110 0010

A << 1 = 0101 1000 // left shift B << 2 = 0011 1000

right shift - signed && left bit 1 if both these conditions are true, then fill the left with 1's otherwise 0's

B >> 3 = 0000 1001 A >> 2 = 1110 1011