Are string literals const?

They are of type char[N] where N is the number of characters including the terminating \0. So yes you can assign them to char*, but you still cannot write to them (the effect will be undefined). Wrt argv: It points to an array of pointers to strings. Those strings are explicitly modifiable. You can change … Read more

Why is the non-const member function being called, instead of the const one?

If you have two overloads that differ only in their const-ness, then the compiler resolves the call based on whether *this is const or not. In your example code, test is not const, so the non-const overload is called. If you did this: testType test; const testType &test2 = test; test2->x(); you should see that … Read more

Can we change the value of an object defined with const through pointers?

It’s “undefined behavior,” meaning that based on the standard you can’t predict what will happen when you try this. It may do different things depending on the particular machine, compiler, and state of the program. In this case, what will most often happen is that the answer will be “yes.” A variable, const or not, … Read more

typedef pointer const weirdness

Note that typedef int* intptr; const intptr x; is not the same as: const int* x; intptr is pointer to int. const intptr is constant pointer to int, not pointer to constant int. so, after a typedef pointer, i can’t make it const to the content anymore? There are some ugly ways, such as gcc’s … Read more

What is the difference between constant variables and final variables in java?

Constant is the concept, the property of the variable. final is the java keyword to declare a constant variable. As other people pointed out, from a semantic/linguistic point of view the expression constant variable is an oxymoron and, as such, we could argue about its correctness. Quoting the specification, anyway, we can read A variable … Read more

Declare a TDateTime as a Const in Delphi

Ok, my reaction is a bit late, but here’s a solution for the newer Delphi’s. It uses implicit class overloaders so that records of this type can be used as if they are TDateTime variables. TDateRec = record year,month,day,hour,minute,second,millisecond:word; class operator implicit(aDateRec:TDateRec):TDateTime; class operator implicit(aDateTime:TDateTime):TDateRec; // not needed class operator implicit(aDateRec:TDateRec):String; // not needed class … Read more

const usage with pointers in C

const char* is, as you said, a pointer to a char, where you can’t change the value of the char (at least not through the pointer (without casting the constness away)). char* const is a pointer to a char, where you can change the char, but you can’t make the pointer point to a different … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)