1 / 17

Simple Data Types and Statements

Simple Data Types and Statements. Namespaces. namespace MyNamespace { // …. { MyNamespace :: func1() using namespace OtherNamespace; Comments: // /* xxxx */. Basic Data Types. Type Range Literals/constants and variables Operators and expressions Assignment Input and output.

mheather
Download Presentation

Simple Data Types and Statements

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Simple Data Types and Statements

  2. Namespaces namespaceMyNamespace { // …. { 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) int x = y = z = 200; 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 chara = ‘A’; // character ‘A’ Charb = L‘A’; // unicode ‘A’ Char c = L‘\x0041’; // hex 41 is ASCII ‘A’ chard = ‘\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. More examples: • ++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 >> 00001011 (twice /2) 00101100 <<10110000 (twice *2) • a = a+5; b = b*2; be a += 5; b *= 2;

  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<0 || x>100 • bFound != Found;

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

  17. Examples • Quadratic Equation: ax2+bx+c=0 • Discriminant: ∆=b2-4ac • Two roots: x1= x2=

More Related