Data Types and Type Conversions.13103
Data Types and Type Conversions.13103
CONVERSION IN C
LANGUAGE
Introduction
• Data types in c refer to an extensive system used for declaring variables or functions of different types.
• The type of a variable determines how much space it occupies in storage and how the bit pattern stored
is interpreted.
1. Basic Types
They are arithmetic types and are further classified into:
(a) integer types
(b) floating-point types.
Enumerated types
They are again arithmetic types and they are used to define variables that can only assign certain discrete
integer values throughout the program.
Derived types
They include :
(a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types.
Following are the examples of some very common data types used in C:
• char: The most basic data type in C. It stores a single character and requires a single byte of memory in
almost all compilers.
• int: As the name suggests, an int variable is used to store an integer.
• float: It is used to store decimal numbers (numbers with floating point value) with single precision.
• double: It is used to store decimal numbers (numbers with floating point value) with double precision.
Different data types also have different ranges up to which they can store numbers. These ranges may
vary from compiler to compiler.
Type conversion in C Language
• It is a concept of converting one data type values into another data type. Typecasting is performing by
using the cast operator. The compiler will automatically change one type of data into another if it
makes sense.
• For instance, if you assign an integer value to a floating-point variable, the compiler will convert the
int to float. Casting allows you to make this type of conversion explicit, or to force it when it wouldn’t
normally happen
Output
Explicit Type Conversion
C++
C++ is a general purpose, object-oriented, middle-level programming language and is an extension of C
language, which makes it possible to code C++ in a “C style”. In some situations, coding can be done in
either format, making C++ an example of a hybrid language.
C#
Pronounced C-sharp (not C-hashtag), C# is a multi-paradigm programming language that features strong
typing, imperative, declarative, functional, generic, object-oriented and component-oriented disciplines.
Advantages of Type Conversion
• This is done to take advantage of certain features of type hierarchies or type representations.
• It helps us to compute expressions containing variables of different data types.
Quiz
Answer - C
Quiz
Answer - B
Quiz
Answer - B
Quiz
Quiz
Answer - B
Quiz
Quiz
Answer - A
THANK YOU!