HI everyone can you help by finding the error in these codes. Can you explain it.
short *numPtr, result;
void *genericPtr = numPtr;
result = *genericPtr + 7;
char s = "this is a character array";
for ( ; *s != '\0'; ++s)
cout << *s << ' ';
double x = 19.34;
double xPtr = &x;
cout << xPtr << endl;
Last edited on
I just find out the second one which we have to change increment to a pointer.
for (; *s != '\0'; ++*s)
is it Right?!
First: You can't use pointer ariphmetic on void pointers.
Second: You cannot increment array pointer.
Third: You are trying to store pointer in double.
Next time do your homework yourself.
You didn't even compile those snippets, did you?
Your answer to the first question has a mistake, as that isn't pointer arithmetic, but you cannot dereference a void pointer.