Does unnessesary and dangerous c-style cast.
you can simply write: char * abc = "1ns";
But any attempt to change abc sting value like abc[1] = 'T'; will lead to segfault.
Best variant: constchar * abc = "1ns";: it is safe and syntaxically correct.
(char*)something is a c-style cast. In C++ you should use static_cast<char*>(something)
Non-Constant Pointer to Constant Data: The address of the pointer can be change. The data pointed to by the pointer cannot be changed.
1 2 3 4
int x = 5, y = 6;
constint * iPtr = &x;
*iPtr = 6; // Error: the value pointed to cannot be changed
iPtr = &y; // You can change the address of the pointer
strcopy() works fine when you are using it for initial variable ititialization. Beacause you know in advance both array and literal constant size. My code with it was just an example of what that code equivalent to.
@abhishekm71:
1) We are declaring data variable points to as const. You still can change where pointer is point to.
2) Sorry, my bad. Drop the const: char abc[] = "1ns";