Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What's the difference between$ char w and$ char char w?


Asked by Raya Mayer on Nov 30, 2021 FAQ



$CHAR w. specifies the width of the output field. The $CHAR w. format is identical to the $ w. format. The $CHAR w. and $ w. formats do not trim leading blanks. To trim leading blanks, use the LEFT function to left align character data.
Keeping this in consideration,
char is used for so called ANSI family of functions (typically function name ends with A ), or more commonly known as using ASCII character set. wchar_t is used for new so called Unicode (or Wide) family of functions (typically function name ends with W ), which use UTF-16 character set. It is very similar to UCS-2, but not quite it.
In fact, char *str = "Test"; is a pointer to the literal (const) string "Test". The main difference between them is that the first is an array and the other one is a pointer. The array owns its contents, which happen to be a copy of "Test", while the pointer simply refers to the contents of the string (which in this case is immutable).
Next,
There is not much difference between the 2 and both can be seen as correct. Due to the long legacy of C code, the string literals have had a type of char [], not const char [], and there are lots of older code that likewise accept char * instead of const char *, even when they do not modify the arguments.
Consequently,
char is a primitive type that represents a single 16 bit Unicode character while Character is a wrapper class that allows us to use char primitive concept in OOP-kind of way.