Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.

Similar presentations


Presentation on theme: "Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx."— Presentation transcript:

1 Simple Data Types and Statements

2 Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx */

3 Basic Data Types Type Range Literals/constants and variables Operators and expressions Assignment Input and output

4 Primitive Data Types in C++/CLI Integer: –Int16 (short); UInt16 (unsinged short) –Int32 (int or long); UInt32(unsigned int or long) –Int64 (long long); UInt64(unsigned long long, _int64) int x, y(1), z = 123; //(signed, 32 bits) Console::WriteLine(0x10); Console::WriteLine(-0x10); // negative hex 10 is base-10 -16 Floating: –Single (float, 32bits) –Double (double, 64bits)

5 Primitive Data Types in C++/CLI Boolean (bool, true or false) Character (Char, 16bits, unsigned unicode) –Character and escape sequence char a = ‘A’; // character ‘A’ Char b = L‘A’; // unicode ‘A’ Char c = L‘\x0041’; // hex 41 is ASCII ‘A’ char d = ‘\t’; // tab escape Char e = L‘\\’; // unicode backslash escape

6 Arithmetic Operators + addition - subtraction * multiplication / division % remainder or modulus

7 Arithmetic Expression(informal and Inexhaustible) A constant is an expression. A variable is an expression. If P and Q are expressions, and ☺ is a binary operator, then P☺Q is an expression. An expression has a type too.

8 Unary Operators +, plus -, minus ++, increment --, decrement

9 Relational Operators == equal to != not equal to > greater than >= greater than or equal to < less than <= less than or equal to

10 Bitwise and Shift Operators ~, unary bitwise complement &, bitwise AND |, bitwise OR ^, bitwise exclusive OR <<, shift left >>, shift right

11 Logical Operators &&, AND ||, OR !, NOT

12 Precedence and Associativity ++, --, unary minus, !, ~ *, /, % +, - >, >= ==, != & ^ | && || ?: =, +=, …

13 ++d, d++: (++d –e) be ++d then - e (d++ - e) be: d-b then d++ int a = 2; int b = 3; int c = (b++,a = b++ * a++, a%b); Be: b++, a*b, b++, a++, a%b Bitwise 0101 & 0011 be 0001 0101 | 0011 be 0111 0101 ^ 0011 be 0110 ~0101 be 1010 00101100 >> 2 be 00001011 (two positions, /4) 00101100 << 1 be 01011000 (one, *2) a = a+5; b = b*2; be a += 5; b *= 2; More examples:

14 Expressions and Assignments y=a*x*x+b*x+c; y=(a*x+b)*x+c; n=7/3; n=7%3; z=x+y/2; z=(x+y)/2; i=i+1; i += 1; i++;

15 More Expressions x>=0 x+y > 3*z+5 x>=0 && x<=100 x 100 bFound != Found;

16 Ternary Operator X?Y:Z (grade>=60)?1:0

17 Examples Quadratic Equation: ax 2 +bx+c=0 Discriminant: ∆=b 2 -4ac Two roots: x 1 = x 2 = Math class: System::Math::Sqrt(discriminant)


Download ppt "Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx."

Similar presentations


Ads by Google