Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
- - prefix in C??
Name: Dado Date: October 5, 2003 at 13:23:21 Pacific OS: Me CPU/Ram: 512MB
Comment:
I have a question about -- prefix. It subtracts 1 from the variable, but when I put --sub_total for a new variable (newsub=--sub_total), it subtracts 1 for newsub and my sub_total also. Why does it do this? When I take the line newsub=--sub_total, my sub_total is good, and as soon as I introduce a --prefix in another equation, it affects the original sub_total too. Help appreciated!
Name: Don Arnett Date: October 5, 2003 at 22:33:25 Pacific
Reply:
The prefix minus decrements the variable and then the variable's (new) value is used in the rest of the statement.
subTotal = 10; newsub = --subTotal;
subTotal is decremented to 9 and then the new value of subTotal (9) is assigned to newsub. So both newsub and subTotal will be 9.
The postfix minus will use the value of the variable in the statement and then decrement the variable.
subTotal = 10; newsub = subTotal--;
The value of subTotal (10) is assigned to newsub and then subTotal is decremented. So, newsub will be 10 and subTotal 9.
Hope this helps.
0
Response Number 2
Name: Dado Date: October 6, 2003 at 13:57:25 Pacific
Reply:
Thank you for the reply. What if I don't want to decrement subTotal, but only decrement newsub by 1 using subTotal, can this method still be used? In other words, in both of your examples, subTotal is decremented, can subnew be the only one decremented, and can you leave subTotal the same using this method?
0
Response Number 3
Name: Dado Date: October 6, 2003 at 18:46:43 Pacific
Reply:
I've found a way how to do it, no need to worry about it.
Summary: I was loking for a really good tutorial about pointers and their use in C/C++ but none of he books I've read was good enough; if anyone can give me a link or somethig, please do it!!! ...
Summary: can any body explain what does this func do in C: int Mparse (int j, int val1, int val2) { return ((int) (fmod(j, pow(2, v1)) / pow(2, v2))); } ...
Summary: In the small program described below, is there some kind of special 'null' character in C (NOT '\0' of course!) which I could pass as the 4th argument, in the 2nd call to 'printFunction()', to get the...