C Fundamental Part3
C Fundamental Part3
Data Types
Data types define the type of data that a variable can hold.
C provides several data types to handle various kinds of data, such as
integers, floating-point numbers, and characters etc.
Primitive data types are the fundamental data types provided by the C
language. They are used to represent simple values like integers,
floating-point numbers, characters and void.
Non-primitive data types are derived from primitive data types. These
data types can hold multiple values like array, pointer, structure, union
etc.
i. int :
it is used to represent integer numbers(whole number) (+ve or -ve).
There are some variants of int data type like long, long long , etc.
Output:
ii. float/double:
Representation of float/double-
It is always signed, meaning it can hold both positive and negative values
The reason float cannot be unsigned in C is due to the nature of real
numbers.
Real numbers, unlike integers, can be positive, negative, or zero.
To represent this full range of values accurately, a floating-point number
needs a sign bit to distinguish between positive and negative values.
Example:
iii. char:
Characters in C are used to represent individual symbols, such as letters,
digits, punctuation marks, and special characters.
They are typically stored as a single byte (8 bits) .
It can represent both signed and unsigned characters.
The null character at the end indicates the end of the string.
Example:
In above code, %c gives chracter ‘5’ ,%d gives ASCII value(integer) of ‘A’.