Datatypes are a class of information that the programme uses. To put it another way, it is employed to declare variables. Datatype describes the kind of data we entered and how we input it in our programme. There are two different sorts of datatypes:
Doubles and Float
A float can have a value between -3.4e38 and +3.4e38 and takes up four bytes in memory. If this is irrelevant, C provides a double data type with a memory footprint of 8 bytes and a range of -1.7e308 to +1.7e308. Double a population can be used to declare a variable of type double;
If the case calls for the use of a real number that is even outside the double data type’s range, a long double is available that has a range of -1.7e4932 to +1.7e4932. In memory, a long double takes up 10 bytes.
You would notice that most of the time while using chars or int in C programming, and instances where using floats doubles or long doubles would be used are indeed rare.
Long and short integer
The integer data type is available in C in a variant that allows short and long integer values. These variations are offered with the goal of offering integers with various ranges whenever possible. Short and long integers would typically take up two and four bytes, respectively, though this is not a rule. Subject to the following restriction, each compiler can choose the proper sizes based on the hardware and operating system for which it is being written.
Shorts must be at least 2 bytes in size, while longs must be at least 4 bytes in size. C. Integers are never larger than shorts, and d. Longs are never larger than integers.
signed and unsigned integer
In some circumstances, such as when an integer variable is exclusively used to count items, we may predict in advance that the number stored there will always be positive. In this situation, we can indicate that the variable is unsigned, as in,
in num_student is unsigned;
The size of the integers in this figure depends on the OS being used.
Compiler | short | int | long |
16-bit (Tutbo C/C++) | 2 | 2 | 4 |
32-bit (Visual C++) | 2 | 4 | int |
long variables which hold long integers are declared using the keywords long, as in,
long int i; long int abc;
Although the programme runs a little bit slower with long numbers, the range of possible values has greatly increased. A long integer’s value typically ranges from -2147483648 to +2147483647. You need more than this unless you’re conducting a global census.
If there are large integers, then symmetry also requires short integers, which take up less memory and speed up programme performance. Short integer is denoted as short int j; short int height; C permits short int and long int to be abbreviated as short and long, respectively. Therefore, the statement mentioned above can be expressed as,
long i ; long abc ; short j ; short height ;
Of course, the majority of C programmers favour this shortcut.
The constant may be tiny enough to be an int in some cases, but we still want to give it as much storage as a long. As in 23L, we append the sumx ‘L’ or ‘I’ to the end of the integer in these circumstances.
There are exits signed and unsigned chars, which have different ranges but are similar to signed and unsigned ints (either short or long). These chars are both signed and unsigned and take up one byte each. Initially, it would seem unusual how a character could have a sign. thought about the statement.
ch char = ‘A’;
Descent Datatype
The derived datatypes are union, struct, pointer, array, and pointer.
Array:
Same as any other language, Array in C stores multiple values of the same data type. That means we can have an array of integers, chars, floats, doubles, etc
int numbers [ ] = ;
double numbers [7];
float interest [5] = ;
The array needs to be either initialized, or the size needs to be specified during the declaration.
Pointer
A pointer can be used to store the addresses of variables of any sort of data. Contrary to popular belief, pointers are not complicated in C. A pointer is only a variable that stores the address of another variable, to put it simply. As a result, C now supports dynamic memory allocation. Pointers are useful for referencing variables while passing them.
The ‘*’ operator is used to define the pointer. For instance –
int*ptr;
This shows that an address, not a value, is stored by ptr. We use the dereference operator “&” to obtain the variable’s address. A pointer is 2 bytes in size. Pointers can’t be combined, divided, or added to. But we can take them away. This will enable us to determine how many components are present between the two subtracted pointers.
Struct:
A struct is a composite structure that can contain variables of different data types. For example, all the student data we declared earlier in basic data types can be put under one structure. Instead of having the information scattered, when we give it a structure, it is easier to store information about more students.
Student;
typedef
struct{
char name [25]; int id;
char group;
float marks [5];
double interest;
}Student;
Union
With a union, you can store different data types in the same memory location. The union can have many members, but only one member can have a value at one time. Union, is thus, a
special kind of data type in C.
The union is defined in the same way as a structure but with the keyword union.
char name [25]; int id;
char group; float marks [5]; double interest;
}st1,st2; union Student