MSL2009. C language

729 views

Published on

Presentation about C language done at Master on Free Software 2009 Edition

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
729
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

MSL2009. C language

  1. 1. C language Juan A. Suárez Romero Master on Free Software
  2. 2. List of topics ● History ● Control structures ● Data types ● Operators ● Preprocessor Master on Free Software
  3. 3. History ● Developed by Dennis Ritchie ● Goal: port a SO from PDP-7 to PDP-8 ● K&R C ● Ansi C (C89/C90 - C99) Master on Free Software
  4. 4. Example #include <stdio.h> int main(int argc, char *argv[]) { printf (“Hello, world!n”); return 0; } Master on Free Software
  5. 5. Control structures while (condition) statement_set; do statement_set while (condition) for (initial_cond, final_cond, change_action) statement_set if (condition) st_set else st_set2; Master on Free Software
  6. 6. Data Types ● Simple types – char, int, float, double – signed/unsigned ● Complex types – arrays, structures, unions – strings (arrays of char ended in NULL) ● 'Special' types – Pointers – Void Master on Free Software
  7. 7. Data types #include <stdio.h> int main(int argc, char *argv[]) { char letter; double pi; float height; int first_prime_numbers[30]; } Master on Free Software
  8. 8. Data types struct email { int sent_date; char *sender; char *subject; char *content; }; struct email *myemail; Master on Free Software
  9. 9. Arrays / pointers ● Array is actually a pointer to a chunk of memory ● Uses of * and &    char *a;    char b;    *a?? &b?? (a = &b)?? (b = *a)?? ● Pointer arithmetic: a[3] == *(a+3) Master on Free Software
  10. 10. Operators ● Arithmetic (+, -, *, /, %) ● Logical (&&, ||, ==, !=, >=, <=) ● Increment / Decrement ● Size of a type ● Self assignment (+=, -=, ...) Master on Free Software
  11. 11. Preprocessor ● Definitions – #define, #undef ● Conditional compiling – #if, #ifdef, #ifndef, #else, #endif ● Include other files – #include Master on Free Software
  12. 12. Functions int multiply (int n1, int n2); int multiply (int n1, int n2) {        return n1*n2; } Master on Free Software
  13. 13. References ● The C Programming Language (2nd edition) – Brian W. Kernighan – Dennis M. Ritchie Master on Free Software

×