1. ## multiple pointer program

pretty basic, first pointer program i have written. format is for a*b=c.
a has pointer *x, b has pointer *p, and **y, and c has pointer *q, **r, ***z. using *x, **y, and ***z to print results. it gives me error on line 23. i have tried quite a few different ways of writing the multiplication but i cant figure out how i am supposed to write it. i want x times y to equal z. and then print all 3.

Code:
```#include <stdio.h>
#include <stdlib.h>

int main()
{

int a;
int b;
int c;
int* x;
int* p;
int* q;
int** y;
int** r;
int*** z;

x=&a;
y=p=&b;
z=r=q=&c;

printf("Enter 2 multiplicands:\n");
scanf("%d %d", &x, &y);
z = (x) * (y);

printf("multiplicands and result are: %d %d %d", x, y, z);

return 0;
}```

2. pointers are as follows:
x points to a
y points to p points to b
z points to r points to q points to c

3. Try compiling with warnings on.
Code:
`y=p=&b;`
That doesn't do what you want it to do. You need:
Code:
```p = &b;
y = &p;```
Also, you have to dereference points if you want to get what they point at. You should stop with trying to use *** and ** before you understand *.

Quzah.

4. Indeed - in your second post you've written statements like "z points to r points to q points to c", but that's not what you code is doing. I suggest having 1 assignment to set up each pointer, even if you could put them all on the same line. quzah has given you a couple already....

At each point in your program, you need to understand how much dereferencing is needed to get to whatever it is you're trying to get to. Your multiplcation for example: currently you're trying to multiply 2 pointers together. Presumably you want to multiply the data items pointed to together. Scribble down the relationships on a piece of paper if you haven't already.

Another place that needs consideration (but won't give you an error!) is scanf:
Code:
`    scanf("%d %d", &x, &y);`
scanf will read 2 ints and stick them in the memory pointed to by the arguments. So in this case the first int read would be stored at the address pointed to by &x. That is x. That means the scanf will overwrite your pointer x with a value read from stdin! You usually need to take the address of a variable when passing to scanf (with & operator) because you need to pass a pointer. In your code x is a pointer to a, so.... do you need the & operator?

5. ok, how else can i point to a pointer? im a bit confused. the assignment is as follows:

Write a program that creates the structure shown in the figure below and reads data into a and b using the pointers x and y. The program then multiplies the value of a by b and stores the results in c using the pointers x, y, and z. Finally, it prints all three variables using the pointers x, y, and z.

z
|
y r
| |
x p q
| | |
a b c

x y and z point to a b and c. b also has p pointer and c also has q then r pointer i guess is how i should say it.
this program works fine. the only error i get it for the multiplication line...
Code:
```#include <stdio.h>
#include <stdlib.h>

int main()
{

int a;
int* p;
int** q;
int** r;
int*** s;
int*** t;
int*** u;
int*** v;

printf("Enter a value:\t");
scanf("%d", &a);

p=&a;
q=r=&p;
s=t=&q;
u=v=&r;

printf("\nValue is: %d\t\n", ***u);
return 0;
}```

6. ok so written like this, they are all seperate. i am not sure what you mean by deferencing my points though. i need to use x p and q instead of x y and z?

Code:
```#include <stdio.h>
#include <stdlib.h>

int main()
{

int a;
int b;
int c;
int* x;
int* p;
int* q;
int** y;
int** r;
int*** z;

x=&a;
p=&b;
y=&p;
q=&c;
r=&q;
z=&r;

printf("Enter 2 multiplicands:\n");
scanf("%d %d", *x, **y);
z = x * y;

printf("multiplicands and result are: %d %d %d", *x, **y, ***z);

return 0;
}```

7. Eh, what are you trying to do?

8. Originally Posted by tgarrisoniv
i am not sure what you mean by deferencing my points though.
If you don't understand what dereferencing is, then you shouldn't be trying to use pointers-to-pointers-to-pointers-to type.

Before you do anything else, you should probably read this: Pointers in C - Tutorial - Cprogramming.com

Quzah.