&a
is not a value - it is the address where the value that was typed in the scanf is - the same address as its variable "a". Each address can only have one value - so even if some gymnastics you multiply the value that is in &a
this new value multiplied will be the number in that memory location - a single number for the variables "a", "* b", "* c" and "* d".
That is, even if you do it on more than one line - something like:
...
b = &a;
*b *= 2;
...
When printing
printf("\n%i\n%i\n%i\n",*b,*c,*d);
You will see the same number printed 3 times.
You can not tell what your ultimate goal is, but for this simple case, it's best to use normal variables, not pointers. If you need pointers, you need to get independent memory addresses for them, so they can contain different numbers.
In addition - note that in this situation of the question, you have in fact two distinct attributes to assign: one is the memory address where the contents of your pointer variables will be (you always try to reuse the same address & a) - and another is the numeric value you want to put in that final address (the value of "a" multiplied by different numbers).
If you need to set two distinct values, you need to do two assignments.
Now, for example, if you declare a vector, instead of pointer variables with different names, you'll be in a situation where you already have the addresses created and defined by the compiler, and you just need to assign the values -
#include <stdlib.h>
#include <stdio.h>
int main (void) {
int a;
int b[3];
printf ("\nInforme um valor: ");
scanf ("%i",&a);
for(int i=0, *c=b; i<=3; i++, c++) *c = a * (i + 1);
printf("\n%i\n%i\n%i\n",b[0], b[1], b[2]);
return 0;
}
Line for(int i=0, *c=b; i<=3; i++) *c = a * (i + 1);
initializes for
with variable i
as usual - only a counter, but also a c
pointer that points to the first element of the b
vector. When i is incremented, the c
position is also (The language C
is smart for pointers - c++
in case it will not forward a byte, but the size of the data type int
bytes - and point right to the next element of the b
vector).