Shared Flashcard Set

Details

Introduction Topics
Basic C topics
25
Electrical Engineering
Undergraduate 3
10/02/2012

Additional Electrical Engineering Flashcards

 


 

Cards

Term
Data Structures
Definition
organization of data stored within a program
Term
Algorithms
Definition
procedures for solving problems
Term
Efficiency
Definition

data structures help to organize data in a way that makes algorithms more effective

 

Effective alg -> solve common problems

Term
Abstraction
Definition
data structures provide different ways of abstracting, managing, and stroing data. Allows programs to choose how to understand and represent data
Term
Reusability
Definition
Data Structures can be efficiently reused as they are typically independent of the overall problem being solved.
Term
Modularity
Definition
Defining modules that provide an interface for users to access that module, where the implementation details can be hidden
Term
Readability
Definition
Doc programs so that developers can follow logic
Term
Consistency
Definition
same style, conventions, design, are used
Term
Compiling
Definition
Each source file is compiled separetly. Header files describe what external functions and variables exists. The compiler will generate an object file.
Term
Linking
Definition
Linker combines object files and library code.
Term
Header Files
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
Program Code
Definition
Compiled instructions for executing program
Term
Static Data
Definition
Data that persists throughout program execution (i.e. global vairables)
Term
Stack
Definition

Temorary memory used for function calls

 

Data does not persist after returning from function

Term
Heap
Definition

Dynamically allocated memory

 

malloc()

Term
C Function Calls
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
Pointers
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
Pointer example
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++;

     }

}

Supporting users have an ad free experience!