Dear Fellow coders
I have an array of integers in main() and all elements are given a zero value
int counts[10] = {0,0,0,0,0,0,0,0,0,0}
I am parsing a pointer to this array to another function:
anotherfuntion(counts);
1) void anotherfunction(int *num)
2) {
3) (num)++; /*Compiles without messages but does not increment value to one*/
4) printf(“%d”, *num); /*Prints zero*/
5) }
from within anotherfunction() I want to increment the value in element 0, (counts[0]) by one and then print it out. So far this has not worked.
I have tried reading my original study manual, but this does not include an example of incrementing the value inside an element using “++”. It shows how to move along the array using pointer arithmetic.
I have also tried many variations as follows:
*num++;
*(num)++;
(*(num)++);
*num+0++;
*(num+0)++;
(*num+0)++;
These produce a message “L value required”. My compiler says “An lvalue is an object locator: an expression that designates an object. An example of an lvalue expression is *P, where P is any expression evaluating to a non-null pointer.
A modifiable lvalue is an identifier or expression that relates to an object that can be accessed and legally changed in memory.”
Wow. However, I am sorry to say I do not properly understand this.
I have performed a step through/watch and seen that line 3 does not increment element zero.
I am using Borlands DOS Turbo C++ V 3.0 complier
Any help or guidance appreciated
Stephanos