Error sum pointers in C ?
Error sum pointers in C ?
PHP Code:
|
Your indices are wrong.
And PSE think about your thread-title. If we had known that you want to add array-values, not pointers, our brains could have worked more efficiently on your problem. If you copied the homework-assignment to the post, above, verbatim.., for example. The rants would come in more violently, though. My own inclusive. |
Please use [ CODE] [ /CODE] tags, not [PHP].
Even if it homework, it is a fair question if you ask the proper question. That is, include why you think your code is correct, explain what is going wrong, where and when, and ask an explicit question like: "what is happening when I see this error" I must add (again) to this that we expect you to demonstrate the understanding of this code. If you just copied the code from someone else, and now paste it here because it does not work, we won't do the work for you either. jlinkels |
Just ask, what was the output of that program? How do you know it was wrong?
|
[content edited, please see post #8]
turay, As others have pointed out, your question does not contain enough information to explain what your problem description is. Likely you are already familiar with these guidelines, however if not, please see the LQ Site FAQ for some clear guidance about how to ask a clear question. I would suggest you use the debugger to look at how the variables in your code change so that you can determine where exactly the code flaw is located. As an example, you will be able to single step through this code, examine the variables, the pointers, and the locations which the pointers are referencing. From those available pieces of information, I'm confident that you can determine where the problem is. Please update the forum as to whether or not you have any knowledge as to how to use the debugger. Meanwhile if you wish a reference about how to use GDB, you can check my blog about using GDB, located here |
...
|
The verbiage of my earlier pun actually explains the flaw in that code.
My statement about the debugger is a way to help you to trace the code and thus learn firsthand how to determine the problem with that code. If you're not inclined to do any actual work, that is fine. |
...
|
Quote:
Well apologies if you felt my post was insensitive. I therefore have edited, it, but meanwhile your quote of it remains so there's is no removal of the original prose in case this is something of importance you wish to retain. Please recheck my post (#5) for additional information about how to solve your problem. Please update the forum with your progress and indicate if you require any additional assistance to help you solve this programming problem. Best Regards. |
Thank you all,
I like this Forum, I edited other replies. I found the answer, I should see where pointer is in array then i use ++ or --. Code:
#include <stdio.h> |
but I'm not really sure if that is the correct fix.
May I ask you to do the following: Code:
... Especially there is an interesting line in your solution: Code:
*aPtr++; And again, can you please post not only the code, but the output too. Thanks. |
Hi pan64,
Had to look it up. But what they call Postfix operators like ++ or -- have higher precedence over Unary operators for de-referencing, http://en.cppreference.com/w/c/langu...tor_precedence Therefore that term is interpreted where it will decrement the pointer, prior to de-referencing it. Meanwhile, you are correct, the * does nothing because there is no assignment on the right of that. Therefore the * can go. Nice catch. |
Quote:
|
I would rather see something like:
Code:
... |
All times are GMT -5. The time now is 04:33 PM. |