User Tools

Site Tools


opus:fall2012:jpettie:datapart1

data Keyword 1

passing by reference (function parameter passing) [C++]

Definition

To use the address of a variable as a reference to some sort of data contained in the variable to send to some algorithmic function which can use the variable's data to perform some sort of action or solve a problem.

References

data Keyword - Pointers to Pointers Phase 2

Definition

As we all know, a pointer is a special variable that does not hold a specific value, but rather the address of a value (or another variable). In the case of a “pointers to pointers” relationship, a pointer is used not to point to the address of another value, but to the address of another pointer.

A pointer to a pointer is written in code as **(pointer1) = &pointer2; where *pointer2 points to the address of another value/variable.

References

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

Demonstration

#include <stdio.h>
#include <stdlib.h>
 
int main(){
        int a = 12;
        int *b;
        printf("\n");
        printf("a is located at 0x%X\n", &a);
        printf("b is located at 0x%X\n", &b);
        printf("\n");
        printf("b, when dereferenced, points to %d\n", *b);
        printf("b contains 0x%X\n", b);
        printf("\n");
        b = &a;
        printf("b, when referenced, points to %d\n", *b);
        printf("b contains 0x%X\n", b);
        printf("\n");
        return(0);
}
opus/fall2012/jpettie/datapart1.txt · Last modified: 2012/09/30 23:19 by jpettie