Politechnika Śląska - strona 285

note /search

Line counting - overview

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

Line counting #include /* count lines in input */ int main() { int c, nl; nl = 0; /* the number of lines so far */ while ((c = getchar()) != EOF) if (c == '\n') /* new line found */ nl++; printf("%d\n", nl); return 0; } ...

Local variables - overview

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

Local variables • Variables declared within a function are ”p rivate ” to this function - they are local • No other function can have direct access to them • Such variables are automatic • They come and go with function invocation • They do not retain their values between calls of the function • In...

Multi dimensional arrays

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

Multi-dimensional arrays • C provides rectangular multi-dimensional arrays • Such arrays are much less used than arrays of pointers • A two-dimensional array is a one-dimensional array, each of whose elements is an array • Syntax: like for one-dimensional arrays •

Overloading - overview

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

Overloading typedef struct { float re, im; } cplx; cplx mult(cplx c, float x) { c.re *= x; c.im *= x; return c; } cplx mult(cplx a, cplx b) { cplx res; res.re = a.re * b.re - a.im * b.im; res.im = a.re * b.im + a.im * b.re; return res; } ...

Parameters and result of a function

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

Parameters and result of a function • The first line of power itse lf, int power(int base, int n) declares: the type returned by the function (int) and types and names of parameters • Parameters are like local variables with initially assigned values • Other names: formal argument (in the declarati...

Parameters passed to the main function

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

Parameters passed to the main function int main(int argc, char *argv[]) • argv[0] is the name by which the program was invoked ( argc is at least 1) • If argc is 1, there are no arguments • In the example: echo.exe hello, world • argc is 3 • argv[0] is " echo.exe " • argv[1] is " hel...

Pointers and arrays

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

Pointers and arrays • The name of an array is a synonym for the location of the initial element • Example: double x[5]; double *p; p = x; /* the same as p = &(x[0]); */ *p = 17; p++; /* now p points to x[1] */ *p = 19; /* here x[0]=17, x[1]=19...

Reverse - overview

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

reverse(char s[]) #include /* reverse: reverse string s in place */ void reverse(char s[]) { int c, i, j; for (i = 0, j = strlen(s)-1; i ...

Strdup - overview

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

Strdup • strdup creates a copy of the given string, allocating memory for it by a call to malloc : char *strdup(char *s) /* make a duplicate of s */ { char *p; p = (char *) malloc(strlen(s)+1); /* +1 for '\0' */ if (p != NULL) strcpy(p, s); return p; /* error handling should be done by the caller *...

Derivation of Poynting Vector Analysis - wykład

  • Politechnika Śląska
  • Fields lines and guides
Pobrań: 0
Wyświetleń: 329

Derivation of Poynting Vector Analysis Maxwell's equations convert the above equation to ∂W ∂t = E · (curlH− J) −H· (curl E − 0) (7.10) where the absence of free magnetic charges is emphasised by the placement of a zero in the second bracket. Using the vector identity div(A× B) = B · curl A −...