Write a code that declares an array of size 10 and then assigns
odd integers starting with 1 to each element. Then print the
array using pointer arithmetic. Hint: find pointer to the first
element and then increment.
i have no idea how to start this! someone please help!
int v[10], x=1; //I putted v instead of a. Is not big deal
for(i=0; i<10; i++)
{ v[i] = x; //x is an auxilliary variable because you cannot generate odd numbers using contors
x = x+2; // odd numbers are: 1, 3, 5, 7, 9... so they can be generated by adding 2 to the previous number starting with 1.
}
//the printing part should be like this:
for(i=0; i<10; i++)
{ cout<<v[i]<<" ";
}
and so i meant *i, just like my notes say. *i is pointer (sic)
Dereferencing i produces the value of the first element of the array pointed to by i. The way I wrote prints the contents of the entire array, not only the first element. Have I missed the point?