User Tools

Site Tools


opus:fall2012:dmckinn2:datapart1

data Keyword 1

dynamic memory allocation (malloc/free)

Definition

dynamic memory allocation is the task of allocating a free chunk of memory specific to the size you predetermine in bytes, by using the malloc function. The chunk of memory is not always in the same location hence being “dynamic” instead of static. By using the “free” function, that will release the block of memory back to the system.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

  • wikipedia
  • class
  • Reference 3

data Keyword 1 Phase 2

passing by address (function parameter passing)

Definition

Passing by address is just one of the ways that you pass a variable into a function. This is done not by passing the variable itself, but by passing the variable address. The only uses for this type of variable passing that I have encountered are arrays.

References

Demonstration

Demonstration of the indicated keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

#include <stdio.h>
void tripnum(int *x)
{
*x = (*x) * (*x) * (*x);
}
 
int main ( )
{
int num = 10;
tripnum(&num);
printf(" Value of num is %d\n”, num); // Value of num is 1000
return (0);
}

Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:

lab46:~/src$ gcc -otripnum tripnum.c
lab46:~/src$ ./tripnum
 Value of num is 1000 
opus/fall2012/dmckinn2/datapart1.txt · Last modified: 2012/10/04 19:05 by dmckinn2