Tuesday, March 5, 2024

FUNDAMENTALS DATA TYPES AND A VALID RANGE OF DATATYPES IN C

Fundamental data types and a valid range of data types

  • FUNDAMENTAL DATA TYPES AND A VALID RANGE OF DATA TYPES
  • TYPE CASTING (IMPLICIT AND EXPLICIT) WITH EXAMPLES 

Data is necessary for all programming languages. The information may be presented as signs, symbols, fractions, or full numbers. C makes use of data types to manage all these different kinds of data. Attributes of variables in the C programming language are used to specify data kinds. It is not possible to store two data types in the same place since each data type has its unique data type.


Primitive data types in c: -

The C language preconditions or already defines primitive data types, which is why they are referred to as basic datatypes. All other data types, such as derived and user-defined data types, are built upon them. The four most used data types in C are double, float, int, and char. We dissect each of these data types here.

The following table shows the memory or size consumed by each primary data type in C:


 Type-casting in C

Typecasting is the process of transforming data kinds. It may also be referred to as data conversion or type conversion. Implicit typecasting is a fundamental concept in "C" programming, which is the process of transforming data types without changing their original meaning.

This type of typecasting is crucial if you want to change a variable's data type without also altering the meaning of the values contained inside. Implicit typecasting occurs automatically when a value is copied to a compatible datatype. Converting types follow strict guidelines. The lower-datatype operand is automatically converted to the higher-datatype operand when working with operands of different data types.

It has two types of type-casting

1)      Implicit type-casting

2)      Explicit type-casting

Implicit type-casting

Implicit type casting is required to change data types while maintaining the integrity of the values kept in a variable. Data types must be converted during this procedure without losing any of their original significance. The conversion procedure complies with strict guidelines for type conversion. If the operands have different data types, then an operand with a lower data type will typically be automatically converted to a higher data type.

For ex.


Explicit type-casting  

Implicit type conversion automatically modifies data types. In certain situations, we might need to enforce type conversion. Consider a situation where two explicitly declared non-integer data types are divided and the result is stored in a division variable.

return, var1 = 10, var2 = 3;

var1/var2 is the result.

In this instance, the result was stored after the division on variables var1 and var2.

The "result" variable will have an integer format. When this occurs, the value stored

Because the variable "result" does not take the fraction part into account, it loses meaning.

which is typically obtained by splitting two numbers.

We use explicit typecasting to force the type conversion in such circumstances.

An operator for typecasting is needed. The general typecasting operation syntax is as

follows:

(type-name) expression

In this case,

The type name refers to the common 'C' language datatype.

A statement may consist of a constant, variable, or an actual expression.

Forex; -


When working with various data types, keep in mind the following guidelines for programming practice to prevent data loss:

·       The float should be converted from integer types.

·       Float types ought to be changed to double.

·       Character types need to be transformed into integers.

No comments:

Post a Comment

Featured Post

ASSOCIATION RULE IN MACHINE LEARNING/PYTHON/ARTIFICIAL INTELLIGENCE

Association rule   Rule Evaluation Metrics Applications of Association Rule Learning Advantages of Association Rule Mining Disadvantages of ...

Popular