1 / 14

Practical Course in Computer Systems

This course provides practical training in computer systems using the C/C++ programming language. The course covers topics such as constants, basic types, statements, loops, switch statements, complex types, variables, expressions, pointers, and structures. It also includes examples and literature resources.

clarked
Download Presentation

Practical Course in Computer Systems

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. Practical Course in Computer Systems C/C++ language Jakub Yaghob

  2. Literature and slides • Slides • http://www.ksi.mff.cuni.cz/lectures/NSWI173/index.html

  3. Example Pascal C int f(int p) { int a[10]; for(int k=0;k<10;++k) { p += a[k]; } return p; } function f(p:integer):integer; var k:integer; a:array[1..10] of integer; begin for k:=1 to 10 do begin p := p+a[k]; end f := p; end

  4. Constants • Integer numbers • Decimal number • 123, -18 • Hexadecimal number • 0x7a • Floating point number • -1.234e-5 • String • “foo bar” • Char • ‘a’ • Escape sequence • \n – LF • \r – CR • \t – TAB • \\ – \ • \’ – ’ • \” – ” • \xab – char 0xab

  5. Basic types • Integer types • Base • char, int • Modifiers • short, long • signed, unsigned • Auxiliary • size_t, byte, word • Floating point types • float, double • Other types • void, bool • Implicit conversion

  6. Statements Pascal C Block { } Assignment a = b+c; if(a!=b) S1 else S2 gotolbl;lbl: return 5; • Block • begin end • Assignment • a := b+c; • if a<>b then S1 else S2 • goto 3;3:

  7. Statements – loops Pascal C while(a<b) S do S while(a>=b) for(i=1;i<=10;i+=2) S continue; break; while a<b do S repeat S until a<b; for i:=1 to 10 step 2 do S

  8. Statements – switch Pascal C switch(i) {case 0: S0; break;case 1: S1; break;case 2:case 3: S23; break;default: Soth; break;} case i of 0: S0 1: S1 2,3: S23 otherwise: Sothend;

  9. Complex types Pascal C using a=int[10]; typedefint a[10]; struct b {int x; char y;}; typedefstruct {int x; char y;} b; using pi=int*; typedefint *pi; typea=array[1..10] of integer;b=record x:integer; y:charend;pi=^int;

  10. Variables Pascal C inti,j; a arr; double arm[5]; b br; pi ptr; int *ptrm; vari,j : integer;arr : a;arm : array [1..5] of real;br : b;ptr : pi;ptrm : ^integer;

  11. Expression Pascal C Arithmetic +, -, *, /, % ++, -- Comparison <, <=, >, >=, ==, != Bitwise ~, &, |, ^, <<, >> Logical &&, ||, ! Pointers &, * Assignment =, +=, -=, *=, /=, %=, &=, |=, ^= • Arithmetic • +, -, *, div, mod, / • Comparison • <, <=, >, >=, =, <> • Bitwise • not, and, or, xor, shl, shr • Logical • and, or, not • Pointers • @, ^

  12. Remnants Pascal C Comments /* */, // Constants #define C 13 constexprint C = 13; Enumerated type enum e { RED, BLUE, GREEN }; Importing a module #include <system.h> • Comments • { }, // • Constants • const C = 13; • Enumerated type • type e = (RED, BLUE, GREEN); • Importing a module • uses system;

  13. Pointers and structures Pascal C typedef litem *liptr; struct litem { inti; liptr next; }; litem i1,i2; liptr p1=&i1,p2=&i2; int *pi1=&i1.i; i1.i = 10; p2->i = 20; *pi1 = 30; type liptr = ^litem; litem = record i : integer; next : liptr; end; var i1,i2 : litem; p1,p2: liptr; pi1: ^integer; p1:=@ i1; p2:=@i2; i1.i:=10; p2^.i:=20; pi1:=@i1.i; pi1^:=30;

  14. Functions Pascal C int f(inti, int *p, int &r) { *p = i; r = i; return i; } void p() { } function f(i: integer; p: ^integer, var r: integer):integer; begin p^ := i; r :=i; f := i; end; procedure p; begin end;

More Related