CS/COE 1520
pitt.edu/~ach54/cs1520
CS/COE 1520 pitt.edu/~ach54/cs1520 C C Developed by Dennis - - PowerPoint PPT Presentation
CS/COE 1520 pitt.edu/~ach54/cs1520 C C Developed by Dennis Ritchie as a language to build utilities for Unix Grew out of Ritchies work to improve the B programming language The first C Compiler was included with Version 2
pitt.edu/~ach54/cs1520
language to build utilities for Unix
the B programming language
with Version 2 Unix in 1972
reimplemented in C
2
#include <stdio.h> int main(void) { printf("hello, world\n"); }
3
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, char **argv) { char str[25]; srand((unsigned) time(NULL)); unsigned int r = rand() % 100; while(r < 85) { if(r > 75) { printf("%u: so close!\n", r); } else if(r > 45) { printf("%u: Getting there...\n", r); } else { sprintf(str, "%u: Still so far away!\n", r); printf("%s", str); } r = rand() % 100; } printf("OUT!\n"); }
4
5
○ Can be signed or unsigned
○ Can be short or long ○ Can be signed or unsigned
○ Can be long
6
7
8
a variable
○ float grades[50] ○ char hello[] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’} ○ int coords[10][10]
divided by the sizeof the data type
○ int helloSize = sizeof(hello)/sizeof(char)
9
○ char hello[12];
○ strcpy(hello, “Hello World!”);
○ strcpy ○ strcat ○ strlen ○ strcmp ○ ...
10
11
12
Multiline comment */
13
14
15
16
if (r > 75) { //true statements } else if(r > 45) { //else if true } else { //false statements }
17
switch(x) { case val1: case val2: break; default: }
}
} while (condition)
}
18
int max(int a, int b) { if (a > b) { return a; } return b; } max(2,6);
19
○ Formatted string is a string literal with tags that start with % ■ Eg.
○ printf("%u: Getting there...\n", r);
variable
○ sprintf(str, "%u: Still so far away!\n", r);
20
○ Structures ○ Pointers ○ Enums ○ Unions ○ Function pointers ○ Inline functions ○ Bitwise operators ○ Inline assembly ○ ...
21