Please Find the Error.

HI everyone can you help by finding the error in these codes. Can you explain it.

First Code:
1
2
3
short *numPtr, result;
void *genericPtr = numPtr;
result = *genericPtr + 7;


Second:
1
2
3
 char s[] = "this is a character array";
for ( ; *s != '\0'; ++s)
cout << *s << ' ';


Third:
1
2
3
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?

@MiiNiPaa
Your answer to the first question has a mistake, as that isn't pointer arithmetic, but you cannot dereference a void pointer.
Next time do your homework yourself.


first: Thank you for your time to comment on my post,

Second This is not a homework I just want to post this to discuss as you can see in my second post. I would like to make discussion with people who are better than me because I am a beginner in C++.

Yes EssGeEich I tried to compile them but I need some elaborate about how this code work. I thank you so much.
Topic archived. No new replies allowed.