You cannot, by definition, assign values to constants. This is useless information anyway, because the OP's question didn't involve const values in any way. |
You can assign values to constants, although it's a nasty method. You just need a pointer and a typecast (so the compiler doesn't say "Hey! You can't point that non-const pointer to that constant!")
1 2 3 4
|
const int myInt = 0;
int* evilPointer = (unsigned int*)&myInt;
*evilPointer = 1;
|
No constant variables were harmed in the making of this nasty hack.
Anyway...
he was trying to set first_number and second_number to 0 but not declaring it as const, but then later he asks the user to read in a value to firstnumber |
If he wants the user to input some values into first_number and second_number, then clearly he doesn't
want to use constants. The whole point of constants is that you can be assured that they haven't been changed by some function somewhere along the line (unless that function happens to have been written by me, in which case, indiscriminate and somewhat evil use of pointers may have occurred).
To be perfectly honest, i used to aswell except like you mentioned almost every project i've came in on has used them and i've grown accustomed to it so I use it as the main way I declare variables. |
Are you talking about camelCase, or are you referring to the annoying trend of every variable, function, etc. starting with a capital letter? Like this,
int AnnoyinglyNamedFunction()
as apposed to
int lessAnnoyinglyNamedFunction
or like this,
int readbly_named_function()
?
Personally I camelCase variable names and use underscores in unions, structs, functions, etc.
Actually, you know what I just noticed? I use underscores for everything, but camel case in examples. That's weird :l