Hi, I'm not 100% confident on the following terms. I've seen them
used alot and never knew exactly knew what they meant,
so I continued to think of things like "point to this",
"follow the pointer to that" etc. But now that I have a better
understanding of how pointers work I'd like to know what exactly
it means when these terms are used.
Passing by value.
Passing by reference.
Dereference.
Direct Reference.
Indirect Reference.
Here is some sample code, are my
comments correct? Any help would be great.
Also am I correct in assuming that an indirect reference to aCode:#include <stdio.h> #include <stdlib.h> void func1(int *pointer); void func2(int array[]); void func3(int number); int main(void) { int my_array[1000]; int variable = 10; int *x; x = malloc(sizeof(int)); /* Is this considered dereferencing *x? */ *x = 99; free(x); /* Passing by reference? */ func1(&variable); func2(my_array); /* Passing by Value? */ func3(variable); return (0); } void func1(int *pointer) { int value = 5; /* Dereferencing *pointer? */ *pointer = value; } void func2(int array[]) { int subscript = 0; /* Dereferencing array? */ array[subscript] = 15; } void func3(int number) { /* Is this a direct reference to number? */ number = 10; }
variable is the same thing as dereferencing the pointer that
points to its address? Like...
Again any help would be great, the book I'm reading doesn'tCode:int *x; int y = 10; x = &y; /*Dereferencing *x and also an indirect reference to y? */ *x = 15;
use any of these terms, these are just terms
I've heard used on IRC and on the boards sometimes.



LinkBack URL
About LinkBacks


