Explain the cast and size of operations in c language
Answers
Answer:
Type casting is a way to convert a variable from one data type to another data type. For example, if you want to store a long value into a simple integer then you can typecast long to int. ... There are two types of type casting in c language that are Implicit conversions and Explicit Conversions.
The sizeof operator is the most common operator in C. It is a compile-time unary operator and used to compute the size of its operand. It returns the size of a variable. ... When sizeof() is used with the data types, it simply returns the amount of memory allocated to that data type.
Answer:
Converting an expression of a given type into another type is known as type casting. typecasting is more use in c language programming.
Sizeof is a much used operator in the C or C++. It is a compile time unary operator which can be used to compute the size of its operand. The result of sizeof is of unsigned integral type which is usually denoted by size_t. sizeof can be applied to any data-type, including primitive types such as integer and floating-point types, pointer types, or compound datatypes such as Structure, union etc. sizeof() operator is used in different way according to the operand type.
When sizeof() is used with the data types such as int, float, char, etc. it simply returns the amount of memory as allocated to that data types.
It is best practice to convert lower data type to higher data type to avoid data loss. Data will be truncated when the higher data type is converted to lower. For example, if a float is converted to int, data which is present after the decimal point will be lost.