here is the original codes that has been set in the question paper:

#include <stdio.h>
#define numitems 10
int main(int argc, char* argv[])
{
int data[numitems];
int i;
int *ptr;
for(ptr = data; ptr < &data[numitems]; ptr++)
*ptr = 0;
for (i=0;i<numitems;i++)
printf("data[%d]=%d\n", i, data[i]);
return 0;
}


HERE ARE MY MODIFICATION BUT STILL NOTHING IS BEING DISPLAYED:

    #include <stdio.h>
#define numitems 10
int main(int argc, char* argv[])
{
int data[numitems];
int i;
int *ptr;
for(ptr = data; ptr < &data[numitems]; (ptr=ptr+2)){
*ptr = 2;

}
for (i=0;i<numitems;i++)
{
printf("data[%d]=%d\n", i, data[i]);
}
return 0;
}

Hi [nitish.mohiputlall],

When I compiled and run the first code you gave. All the element in the array were all initialized to 0. All that were displayed on the CLI.
But while using the second set of codes because of (ptr=ptr+2) all the odd element of the array weren't initialized to 2. So, if you have that changed to what was used in the original program i.e ptr++ you should have what you wanted.

HERE ARE MY MODIFICATION BUT STILL NOTHING IS BEING DISPLAYED:

if I may ask how do you mean nothing is being displayed? And hope you understand what is happening or going on in the first for loop?

it should have displayed multiples of 2 starting from 2 till 20

Modify the first Loop so that the values in the array data are initialized to multiples of 2 as follows: 2,4,6,....,20. when i posted the question it did not take everything

Hi nitish.mohiputlall,

Am sorry, I can no longer help because, this is suppose to be an exam question, except you can proof otherwise.

However, what you have to do is not difficult, just a little checking of your code will reveal that.
I hope you understand that.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.