What Happens When a Float Expression Is Read Into an Int Variable
C++ Data Types
All variables utilise information-type during declaration to restrict the type of data to exist stored. Therefore, nosotros can say that information types are used to tell the variables the type of data it can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable based on the data-type with which information technology is declared. Every data type requires a different amount of memory.
Data types in C++ is mainly divided into three types:
- Primitive Information Types: These information types are built-in or predefined data types and can be used directly by the user to declare variables. example: int, char , float, bool etc. Archaic data types available in C++ are:
- Integer
- Graphic symbol
- Boolean
- Floating Point
- Double Floating Point
- Valueless or Void
- Wide Character
- Derived Information Types: The data-types that are derived from the primitive or built-in datatypes are referred to as Derived Data Types. These can exist of four types namely:
- Role
- Array
- Pointer
- Reference
- Abstract or User-Divers Data Types: These information types are defined past user itself. Like, defining a form in C++ or a structure. C++ provides the post-obit user-defined datatypes:
- Course
- Structure
- Spousal relationship
- Enumeration
- Typedef divers DataType
This article discusses archaic data types available in C++.
- Integer: Keyword used for integer data types is int. Integers typically requires four bytes of retentivity space and ranges from -2147483648 to 2147483647.
- Character: Character information blazon is used for storing characters. Keyword used for character data type is char. Characters typically requires one byte of memory space and ranges from -128 to 127 or 0 to 255.
- Boolean: Boolean data type is used for storing boolean or logical values. A boolean variable can store either truthful or false. Keyword used for boolean data blazon is bool.
- Floating Indicate: Floating Point data type is used for storing single precision floating indicate values or decimal values. Keyword used for floating point data blazon is float. Bladder variables typically requires iv byte of retention space.
- Double Floating Indicate: Double Floating Bespeak data blazon is used for storing double precision floating indicate values or decimal values. Keyword used for double floating signal data type is double. Double variables typically requires 8 byte of memory infinite.
- void: Void means without any value. void datatype represents a valueless entity. Void data type is used for those function which does not returns a value.
- Wide Character: Wide character data type is also a character data type only this data blazon has size greater than the normal 8-bit datatype. Represented past wchar_t. It is by and large 2 or 4 bytes long.
Datatype Modifiers
As the name implies, datatype modifiers are used with the congenital-in information types to alter the length of information that a particular data blazon can concur.
Data type modifiers available in C++ are:
- Signed
- Unsigned
- Curt
- Long
Below table summarizes the modified size and range of born datatypes when combined with the blazon modifiers:
Data Type | Size (in bytes) | Range |
---|---|---|
curt int | 2 | -32,768 to 32,767 |
unsigned short int | 2 | 0 to 65,535 |
unsigned int | iv | 0 to 4,294,967,295 |
int | four | -ii,147,483,648 to 2,147,483,647 |
long int | 4 | -2,147,483,648 to 2,147,483,647 |
unsigned long int | four | 0 to iv,294,967,295 |
long long int | viii | -(2^63) to (ii^63)-1 |
unsigned long long int | 8 | 0 to 18,446,744,073,709,551,615 |
signed char | one | -128 to 127 |
unsigned char | i | 0 to 255 |
float | four | |
double | eight | |
long double | 12 | |
wchar_t | ii or iv | one wide character |
Annotation : Above values may vary from compiler to compiler. In the above example, we have considered GCC 32 bit.
We tin display the size of all the data types by using the sizeof() operator and passing the keyword of the datatype every bit argument to this part every bit shown below:
CPP
#include<iostream>
using
namespace
std;
int
main()
{
cout <<
"Size of char : "
<<
sizeof
(
char
)
<<
" byte"
<< endl;
cout <<
"Size of int : "
<<
sizeof
(
int
)
<<
" bytes"
<< endl;
cout <<
"Size of short int : "
<<
sizeof
(
brusque
int
)
<<
" bytes"
<< endl;
cout <<
"Size of long int : "
<<
sizeof
(
long
int
)
<<
" bytes"
<< endl;
cout <<
"Size of signed long int : "
<<
sizeof
(
signed
long
int
)
<<
" bytes"
<< endl;
cout <<
"Size of unsigned long int : "
<<
sizeof
(unsigned
long
int
)
<<
" bytes"
<< endl;
cout <<
"Size of bladder : "
<<
sizeof
(
float
)
<<
" bytes"
<<endl;
cout <<
"Size of double : "
<<
sizeof
(
double
)
<<
" bytes"
<< endl;
cout <<
"Size of wchar_t : "
<<
sizeof
(
wchar_t
)
<<
" bytes"
<<endl;
return
0;
}
Output:
Size of char : 1 byte Size of int : 4 bytes Size of curt int : 2 bytes Size of long int : 8 bytes Size of signed long int : eight bytes Size of unsigned long int : eight bytes Size of float : 4 bytes Size of double : viii bytes Size of wchar_t : iv bytes
This article is contributed by Harsh Agarwal. If you similar GeeksforGeeks and would like to contribute, you can also write an commodity using write.geeksforgeeks.org or post your commodity to review-team@geeksforgeeks.org. See your article actualization on the GeeksforGeeks chief folio and help other Geeks.
Please write comments if you find anything incorrect, or y'all want to share more information nearly the topic discussed to a higher place.
marshallwituarmay92.blogspot.com
Source: https://www.geeksforgeeks.org/c-data-types/
0 Response to "What Happens When a Float Expression Is Read Into an Int Variable"
ارسال یک نظر