ap Flashcards
Terms : Hide Images [1]
7576039202 | pointer | variable that stores a memory address | 0 | |
7576064484 | & operator for pointers | references a value, ie gets the memory address for a variable | 1 | |
7576073114 | int x = 5; int *p = &x; printf("%d",*p) | 5 | 2 | |
7576107371 | int x = 5; int *p = &x; printf("%d",*p) *p=9 printf("%d",x) | 9 | 3 | |
7585717046 | Stack variables | only exist inside of their scope/function | 4 | |
7585719745 | static variables | exists in function, retains value after successive calls | 5 | |
7585754204 | global varibles | type of static variable. can be referenced across files using "extern" | 6 | |
7585793281 | * operator for pointers | deferences a pointer --> follows the pointer to get the thing it points to | 7 | |
7585879080 | int a[3] = {0,1,2} int *p=a what is p | p is a pointer to the first element in the array | 8 | |
7585884361 | int a[3] = {0,1,2} int *p=a what's another way to write *p? | &a[0] | 9 | |
7585890636 | how to write a[2] with *p? | *(p+2) | 10 | |
7586005401 | char c[]={'a','b','\0'} char c[]= | "abc" | 11 | |
7591852264 | char c[]="abc" , c points to | "a" | 12 | |
7591853830 | char c[]="abc" , is c incrementable? | no. always points to a, you can do c[i] though | 13 | |
7591858958 | char *s = "my string" | s is a pointer to the first character. is incrementable | 14 | |
7591873119 | declare array of strings | char *a={"hello","world"} | 15 | |
7591989398 | valgrind command | valgrind --leak-check=full ./executable | 16 | |
7604286215 | argv[0] | first argument of command line | 17 | |
7605160650 | argc stands for | argument count | 18 | |
7605163900 | argv stands for | argument vector | 19 | |
7605171664 | argv is a pointer to | an array of character strings, that contain arguments (one per string) | 20 | |
7665791475 | gcc flags | -g and -wall for all, -g for linking | 21 | |
7665810478 | -l flag for ls | more info about each file | 22 | |
7665813688 | -a flag for ls | all files, including hidden | 23 | |
7665823477 | steps for compiling | preprocessing, compiling, linking | 24 | |
7665825497 | preprocessing | eg, #include "file" | 25 | |
7665829103 | compiling | converts c to lower level language, creates .o files | 26 | |
7665833800 | linking | takes several .o files and makes executable | 27 | |
7665860963 | include guards | #ifndef #define #endif | 28 | |
7665863092 | compile a c program | gcc -Wall -g -c main.c | 29 | |
7665866188 | gcc flags for compiling | -Wall -g -c | 30 | |
7665876475 | -g | adds debugging to tell you where code broke | 31 | |
7665880040 | -Wall | compile time warnings` | 32 | |
7665881218 | -c | preprocesses and compiles c | 33 | |
7665883537 | how to link | gcc -g main.o -o main | 34 | |
7665910983 | CFLAGS | compiling flags, -g -Wall | 35 | |
7665914899 | LDFLAGS | linking flags, -g | 36 | |
7665916753 | dependencies for main | main: myadd.o main.o | 37 | |
7665922068 | implicit linking rule | $(CC) $(LDFLAGS) | 38 | |
7665935011 | main.o line in make | main.o: main.c myadd.h | 39 | |
7666109125 | data types | char<= short <= int <=long <=long long | 40 | |
7666158412 | size of char | 1 byte | 41 | |
7666158413 | actual increment | void increment(int * b){ (*b)++ } increment(&a) | 42 | |
7666181342 | p+1 vs *(p+1) | p+1 is pointing to the thing after what p points to *(p+1) is the value of the thing next to what p is pointing to | 43 | |
7666200082 | ways to declare string | char c[]="abc" char c[]={'a','b','c','\0'} char *s="my string" | 44 | |
7666270027 | mallocing | int *p=(int *)malloc(100*(sizeof(int)) | 45 | |
7666318853 | char x = 0 | =0, char x = '\0' = 0 char x = '0' = 48 | 46 | |
7666353270 | bitwise and and or | &, | | 47 |