I have just recently started to learn C. I have been playing around with different code to teach myself. I cannot figure out the following code:
void testfunction (int *);
void testfunction2 (int *);
int main (void)
int number = 5, other_number = 5;
printf("\nnumber in main: %d\n\n", number);
printf("\nother_number in main: %d\n\n", other_number);
void testfunction (int *value)
printf("\nnumber in testfunction: %d\n", *value);
void testfunction2 (int *value)
*value += 1;
printf("\nother_number in testfunction2: %d\n", *value);
For some reason when I run the above program I get this:
Shouldn't both numbers pointers be 6?
number in testfunction: -1077941616
number in main: 5
other_number in testfunction2: 6
other_number in main: 6
Why am I getting this crazy number? Can I not use "++" outside of a loop? "+=" seems to work just fine.
Thanks for the help!!