Syntax | Name | Java's counterpart | use |
---|---|---|---|
char | character | byte | Stores an ASCII code (character) or it can also store a very short integer (−128..127) |
short | short integer | short | uses 2 byte memory, value between −32768 and 32767 |
int | ordinary integer | int | uses 4 byte memory, value between −2147483648 and 2147483647 |
long | long integer | long | uses 8 bytes memory, value between −9223372036854775808 and 9223372036854775807 |
float | single precision float | float | uses 4 byte memory, absolute value between 1.4E−45 and 3.4E38 |
double | double precision float | double | uses 8 byte memory, absolute value between 4.9E−324 and 1.8E308 |
_Bool | boolean | boolean | true (1) or false (0) |
Syntax | Name | use |
---|---|---|
unsigned char | Unsigned character | Very short positive integer (0..255) |
unsigned short | Unsigned short integer | uses 2 byte memory, value between 0 and 65535 |
unsigned int | Unsigned ordinary integer | uses 4 byte memory, value between 0 and 4294967295 |
unsigned long | Unsigned long integer | uses 8 bytes memory, value between 0 and 18446744073709551615 |
* | Reference type | Contains a memory address (usually 4 bytes, but 64 bits machines will use 8 bytes) |
|
float A, B, C; - Defines 3 float variables A = 4; B = 5; C = A + B; |
|
int A; - Defines integer float B, C; - Defines 2 float variables A = 4; // Integer B = 5; // Float C = A + B; - The value of A is converted to FLOAT first - Then the addition is performed |
|
|
|
Here's an explanation of the cvttss2si instruction: click here
How to run the program:
|
However:
|
This will be explained in the automatic conversion rule next....
|
Warning:
|
#include <stdio.h> int main(int argc, char* argv[] ) { int i; short s; i = 9827563; s = i; /* Unsafe conversion, allowed in C !!! */ printf( "i = %d , s = %d \n", i, s ); } |
Output:
i = 9827563 , s = -2837 (lost of accuracy !) |
How to run the program:
|
|
int main(int argc, char* argv[] ) { int i = 0; // Integer // i is a number that you can add, subtract, etc int a[5]; // Array of integers // a is the LOCATION (address) of the first elem of the array i = a; // WARNING !! Too different !!! printf("i = %d\n", i); } |
Compiler message:
casting2.c: In function 'main': casting2.c:11: warning: assignment makes integer from pointer without a cast |
How to run the program:
|