Hey guys, i was just wondering are constants still refered too as variables?
I was also wondering if there such as think as const arrays and if they are commonly used?
thanks.
Hey guys, i was just wondering are constants still refered too as variables?
I was also wondering if there such as think as const arrays and if they are commonly used?
thanks.
when necessary
Kuphryn
When variables are labeled const, they remain variables yes. Unchanging variables.
Functions can be labeled const as well.
But doesn't const in front of a function mean constructor?Originally Posted by Jreak
Const variables generally compile by replacing each call to the variable with it's value. Thus you cannot take the address of a const value.
I'm not sure about const arrays and how they work.
There is no such thing as a const function. However there is such a thing as a const meathod. A const meathod is a meathod that promises not to change any non-mutable value in it's member class.
The key word const is also used extensively to mark function (and meathod) referenced paramitters as not changeing the referenced value.
A constructor takes the same name as it's parent class. If you name a member function myclass() in a class name "myclass", C++ will assume the aforementioned function is the constructor. Honestly, where did you get such notions?
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
If you name a constant function does that mean you can't change the parameters or does it mean it can't be overloaded/overridden or both?
Functions cannot be const. Methods can. A method is a function that is part of an object (and thus not really a function).Originally Posted by bumfluff
If you mark a method const, that means that the method cannot change the object that is a method of. (Unless the parts it changes are explicitly marked mutable).
It is also possible to mark parameters const. This applies to both methods and functions, but it is done on a single parameter basis. That is, each parameter must have its own indicator saying that it's const. Marking parameters const makes the function unable to change the arguements passed by those parameters.