Upload
juan-a-suarez-romero
View
105
Download
2
Embed Size (px)
DESCRIPTION
Presentation about C language done at Master on Free Software 2009 Edition
Citation preview
Master on Free Software
C language
Juan A. Suárez Romero
Master on Free Software
List of topics
● History● Control structures● Data types● Operators● Preprocessor
Master on Free Software
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
Example
#include <stdio.h>
int main(int argc, char *argv[])
{
printf (“Hello, world!\n”);
return 0;
}
Master on Free Software
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
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
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
Data types
struct email {
int sent_date;
char *sender;
char *subject;
char *content;
};
struct email *myemail;
Master on Free Software
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
Operators
● Arithmetic (+, -, *, /, %)● Logical (&&, ||, ==, !=, >=, <=)● Increment / Decrement● Size of a type● Self assignment (+=, -=, ...)
Master on Free Software
Preprocessor
● Definitions– #define, #undef
● Conditional compiling– #if, #ifdef, #ifndef, #else, #endif
● Include other files– #include
Master on Free Software
Functions
int multiply (int n1, int n2);
int multiply (int n1, int n2)
{
return n1*n2;
}
Master on Free Software
References
● The C Programming Language (2nd edition)– Brian W. Kernighan– Dennis M. Ritchie