Fundamentals of Computer Programming - strona 13

note /search

Passing values to functions

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 532

Passing values to functions • All function arguments are passed ''by value'' • The called function gets a copy of arguments • If you really need to modify a variable in a calling routine: - pass a pointer to it - the function will modify this plac...

Programming - overview

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 441

Programming • The CPU understands only machine code Hexacedimal version: 23 D1 8A 06 46 C1 E9 02 47 83 F8 08 Assembler mnemonics: mov al,byte ptr [esi] mov byte ptr [edi],al inc esi shr ecx,2 inc edi cmp ecx,8 assembler is called second generation language ...

Prototypes of functions - overview

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 476

Prototypes of functions • The compiler needs to recognise an identifier as a function name before you use it; the list of parameters should also be known • You may: - define a function before calling it, or - declare a function before calling it using a prototype and define it later • The declarati...

Remove - overview

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 581

remove (unlink) Removes a file specified by filename int remove(const char *filename); • Example: #include int main(void) { char file[80]; /* prompt for file name to delete */

Rewind - overview

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 560

Rewind Repositions the file pointer to the beginning of a file void rewind( FILE * stream ); • repositions the file pointer to the beginning of the file • A call to rewind is similar to (void) fseek( stream , 0L, SEEK_SET ); • unlike fseek , rewin...

Rules of Type conversion

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 434

Type conversions - rules • If there are no unsigned operands, use this set of rules: - If either operand is long double , convert the other to long double . - Otherwise, if either operand is double , convert the other to double . - Otherwise, if e...

Scanf example - overview

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 476

scanf example #include int main() { int x; printf(” Enter a number: ”); scanf(”%d”, &x); printf(”The square of %d is %d\n”, x, x*x); return 0; } Warning: scanf is dangerous. ...

Skipping an iteration - overview

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 406

Skipping an iteration: continue • continue causes the next iteration of the enclosing for , while , or do loop to begin • In while and do : jump to the test part • In for : jump to the increment step (and then test) • The continue does not apply to switch • A continue in switch which is in a loop c...

Strings as arrays - overview

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 420

Strings as arrays • Defining a variable capable of storing strings (texts): as an array of characters: char name[length] for example: char s[10]; • There is a '\0' at the end of the string • Take care about the length! • Functions operating on strings ...

Structures may be returned by functions

  • Politechnika Śląska
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 315

Structures may be returned by functions typedef struct { float re, im; } cplx; cplx mult(cplx c, float x) { c.im *= x; c.re *= x; return c; } ...