1. Thanks for the input guys/gals.........really gonna help me in the final exam! I hope you guys dont mind if I ask more questions later on when I stumble over something I dont understand.

2. Given the memory setup shown, fill in the chart by indicating the data type and value of each reference as well as the name of the function in which the reference would be legal. Give pointer values by referring to cell attributes. For example, the value of valp would be "pointer to color shaded cell," and the value of &many would be "pointer to gray shaded cell."

http://users.tpg.com.au/dogdoo/Cprog/Table.jpg

Code:
```Reference          Where Legal          Data Type          Value

--------------------------------------------------------------------------------------------------------

valp               sub                  double*            pointer to color shaded cell
&many
code
&code
countp
*countp
*valp
letp
&x```
Now, the confusion is the data type of the first one (valp). Its double*. Isnt it suppose to be double, and not double*. I though * is part of *valp, and not part of double*

Like in the following code:

Code:
`double *valp;`

3. Originally Posted by Daveo
Now, the confusion is the data type of the first one (valp). Its double*. Isnt it suppose to be double, and not double*. I though * is part of *valp, and not part of double*
The table clearly shows a pointer (literally) from function sub()'s valp to main()'s x. x is 17.1 so it has to be some kind of floating point type, e.g. double. Maybe this helps to understand it:

Code:
```      // variable x of type double
double x;

// variable valp of type pointer to double
double *valp;

// same as above
double* valp;

// tricky: variable valp of type pointer to double and variable valq of type double (not a pointer to a double).
double* valp, valq;

// same as above, but easier to read (personal opinion)
double *valp, valq;

// this should be easy to figure out now
double valq, *valp= &valq;```
Some other bits of info I thought you might maybe not yet understand in detail:

Functions can take parameters and have one return value. If a function main() calls another function X(), the parameters specified for X() by main() are copied into X()'s scope and can be accessed like local variables. Any modification to those variables will *not* change "their" content in main. After all, they're just copies.
However, if main() passes X() a pointer to one of its (main()'s) variables, X() can use that pointer to modify the data/variable pointed at. It can however still not change the pointer itself in main()'s scope, just its local copy. So pointers are a good way if you need more then one return value or if you want a function to change data at a specific, already existing address in memory, eg. to modify a string.
If you see X* or X * then that's a type of a pointer ("a type X * that can be used to create pointers pointing at variables of type X"), whereas *x (or * x) is a variable x of an (here unspecified) pointer-type - e.g. int *x.

Now when X() has a return value, that value directly modifies the variable to which X() as been assigned, e.g.

Code:
`int x_returned= X();`

4. Do you mean: Trying to point to a variable in function 'main' from a pointer within the body would lead to an error.
there is a typo there , i ment "Trying to point to a variable in function 'main' from a pointer within the body of any other function would lead to an error. "

take this as an example and compare it to our program that uses pointers earlier :
Code:
```#include <stdio.h>

void sum();

int main(void)
{
int result;

sum();

printf("%d", result);

return 0;
}

void sum(void)
{
int *x;
int num1, num2 , sum;

printf("Enter the first number : ");
scanf("%d", &num1);

printf("Enter the second number : ");
scanf("%d", &num2);

sum = num1 + num2;

x = &result     /* we're trying to point to the adresss of 'result'
in function 'main' but we can't */
*x = sum;

}```
we tried to point to 'result' from a pointer within the body of another function but it won't work , why? because 'result' is a local variable and its scope ends with the end of 'main' function.

Are they the same? I like your way, its shorter
" between the parentheses we're telling the computer how many and what kind of arguments our sum function will take (or point to). We declared two int variables without the necissity of specifing their names."

What does the * mean?
the '*' is called the indirection operator , it enables us to refer to target objects. In easy words , you precede a variable in its declaration with a '*' to tell that its a pointer-to-type where type is the type of object its pointing to.

for example :
Code:
```...
int n = 5;
int *p = n;
...```
now 'p' has the memory adress of 'n' , whereas '*p' will be pointing to the value of 'n' wich is 5.

Now, the confusion is the data type of the first one (valp). Its double*. Isnt it suppose to be double, and not double*. I though * is part of *valp, and not part of double*
It's type is 'double *' wich means 'pointer-to-double' , we use it this way to distinguish pointers and regular variables.

p.s : my name isn't 'Brian' its 'Brain' Cell

5. Originally Posted by Daveo
Also, im having a hard time understanding the basics of pointers. Could you guys direct me to the right place, possibly a tutorial on pointers that is not hard, and easy to understand for someone like me who is a novice at C.

I'm surprised no-one's mentioned that there is an tutorial on pointers in the FAQ's.

6. Originally Posted by Jez
I'm surprised no-one's mentioned that there is an tutorial on pointers in the FAQ's.
You mean there is a FAQ here?!

Quzah.

7. Originally Posted by quzah
You mean there is a FAQ here?!

Quzah.
LOL ... i hope that was a sarcastic comment

here's the pointers tutorial from the FAQ. And www.google.com would be your best in finding other tutorials