Term 
         | 
        
        
        Definition 
        
        | organization of data stored within a program |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | procedures for solving problems |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        data structures help to organize data in a way that makes algorithms more effective 
  
Effective alg -> solve common problems  |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | data structures provide different ways of abstracting, managing, and stroing data. Allows programs to choose how to understand and represent data |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | Data Structures can be efficiently reused as they are typically independent of the overall problem being solved. |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | Defining modules that provide an interface for users to access that module, where the implementation details can be hidden |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | Doc programs so that developers can follow logic |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | same style, conventions, design, are used |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | Each source file is compiled separetly. Header files describe what external functions and variables exists. The compiler will generate an object file. |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | Linker combines object files and library code. |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | In order for a fuction defined in the source file to be used by another file, its existance can be defined in a header. |  
          | 
        
        
         | 
        
        
        Term 
        
        | C Program Memory Organization |  
          | 
        
        
        Definition 
        
        Program Code 
----------------- 
Static Data 
------------------ 
Stack 
------------------ 
Heap  |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | Compiled instructions for executing program |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        | Data that persists throughout program execution (i.e. global vairables) |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        Temorary memory used for function calls 
  
Data does not persist after returning from function  |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        Dynamically allocated memory 
  
malloc()  |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        The program stack is used to keep track of information during function calls 
  
This information is referred to as the activation record 
  
Activation Record: include storage for input parameters, return calue, temp storage, saved style information  |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        A C pointer stores the address at which data is located. 
  
Need Methods to: 1- operate on pointers themselves 
2- operate on the data pointed to the pointer  |  
          | 
        
        
         | 
        
        
        Term 
         | 
        
        
        Definition 
        
        int a; 
int *iptr; 
int **iptr_ptr; 
iptr = &a;   //& returns the address of variable (a) location 
*iptr = 10; //* access the item pointed to by the pointer 
iptr_ptr = &iptr; //pointers are also var stored inmemory, so they also have an address  |  
          | 
        
        
         | 
        
        
        Term 
        
        | Array Access using Pointers |  
          | 
        
        
        Definition 
        
        Pointers are commonly used to access arrays. C supports pointer arithmetic to make doing so easy. 
  
-a pointer can be directly assigned to an array. Same as assigning pointer to address of the first element 
-incrementing a pointer will increment the memory location stored to the access the nexr location based on the type of data being accessed.  |  
          | 
        
        
         | 
        
        
        Term 
        
        | Example of arrays access using pointers |  
          | 
        
        
        Definition 
        
        int test_array[100]; 
int sum; 
int *iptr; 
  
for (iptr=test_array; iptr<&test_array[100]; iptr++){ 
             sum += *iptr; 
} 
  
iptr = test_array;      |  test_array[0+5] = 42; 
iptr = &test_array[0]; | iptr = test_array; *(iptr+5)=42; 
   |  
          | 
        
        
         | 
        
        
        Term 
        
        | Dynamic Memory Allocation ways |  
          | 
        
        
        Definition 
        
        we can dynamically allocate memory as needed using malloc, realloc, calloc, and: 
void* malloc(size_t size); 
void* calloc(size_t size); 
void* realloc( void* ptr, size_t size); 
void free(void *ptr);  |  
          | 
        
        
         | 
        
        
        Term 
        
        | Dynamic Memory Allocation cont.. |  
          | 
        
        
        Definition 
        
        | malloc() allocates a block of memory of size bites in the program heap and returns a pointr to the first memory location if successfull. returns NULL of not |  
          | 
        
        
         | 
        
        
        Term 
        
        | Typical method of dynamic memory allocation |  
          | 
        
        
        Definition 
        
        int *iptr; 
iptr = malloc(sizeof(int)); 
if (iprt==NULL{ 
printf("could not allocate memory\n"); 
exit(-1); 
}  |  
          | 
        
        
         | 
        
        
        Term 
        
        | Dynamic Memory Allocation Ptrs to Ptrs |  
          | 
        
        
        Definition 
        
        int g(int **iptr) { 
*iptr = (int*)malloc(sizeof(int) *5); 
if (*iptr == NULL) return -1; 
return 5; 
} 
  
int *new_array; 
int num_elements; 
  
num_elements = g(&new_array); 
if(num_elements >= 0) { 
     int i=0; 
     int aptr = new_array; 
     while (i<num_elements) { 
     *aptr = 0; 
     aptr++; 
     i++; 
     } 
}  |  
          | 
        
        
         |