Hello again gays.
I want to know about casting and type conversion in C programing language . for example how this expression work and what is the return value ?
char *strval ; (const char*)strval ;
where we have permission to use casting ? do I have to set a file attribute.
thanks .
Doing a typecast such as this does not do any data conversion.
The result of the expression is the same with or without the typecast. Only the type of the result changes.
The reason you do a typecast like this is to tell the compiler that you know what you are doing. Without the typecast, the compiler will generate a warning. Warnings tell you that what you have coded is possibly in error or possibly somewhat ambiguous (that is, it is a case where the compiler may not being doing what you expect).
One of the purposes of strong typing such as in C is to help ensure that the compiler is doing what you expect to help reduce bugs. Typecasts override the types. When you do a typecast you should be thinking carefully about the affects of it. For instance, on many computers there is only one type of memory, so "const" is a compiler thing that syntactically stops you from modifying a value. Typecasting away a const attribute will work fine. On many microcontrollers, a const data may be stored in EPROM, so it cannot be modified. Typecasting away a const attribute will leave you with a program that will not in fact modify the data as you expect.
Typecasts do not do data conversion (i.e. strings to numbers) and they can't be used for toasting marshmallows.
It is however a source of much amusement, which I fear will be lost if it changes.