Summary
Below are some tables with summary of data types and format codes. There are more to it than this but for now these are the ones that you will need to worry about.
Description | Data Type | Format Codes | Size | Range (inclusive) |
---|---|---|---|---|
floating point | float | %f | 32 bits - 4 bytes | N/A |
more accurate floating point | double | %lf | 64 bits - 8 bytes | N/A |
characters | char | %c | 8 bits - 1 byte | -128 to 127, values are often used to encode various characters |
whole numbers | int | %d | 32 bits - 4 bytes | -2147483648 to 2147483647 |
small whole numbers | short or short int | %hd | 16 bits - 2 bytes | - 32768 to 32767 |
big whole number | long or long int | %ld | 32 bits - 4 bytes or 64 bits - 8 bytes | -2147483648 to 2147483647 or to |
much bigger whole number | long long or long long int | %lld | 64 bits - 8 bytes | to |
warning
Size/Range information is based on typical current computers. It is not fixed. In older computers for example integers were only 16 bits. If the size changes the range changes.
Outside of the above, the following modifiers can be applied:
unsigned:
- can be applied to integer types (long, int, char, short)
- all bits of the value are used to represent a number without the use of a sign bit
- unsigned int range from 0 to 4294967295 inclusive
- unsigned char range from 0 to 255 inclusive
Check it out for yourself!
Try this program on your computer to see how big the various types are!
#include <stdio.h>
int main(void){
printf("size (number of bytes) of a char: %lu\n", sizeof(char));
printf("size (number of bytes) of a int: %lu\n", sizeof(int));
printf("size (number of bytes) of a float: %lu\n", sizeof(float));
printf("size (number of bytes) of a double: %lu\n", sizeof(double));
printf("size (number of bytes) of a long: %lu\n", sizeof(long));
printf("size (number of bytes) of a short: %lu\n", sizeof(short));
printf("size (number of bytes) of a long long: %lu\n", sizeof(long long));
return 0;
}
Special Characters
Character you want | What to Type |
---|---|
newline | \n |
tab | \t |
backslash ( \ ) | \\ |
percent sign (%) | %% |
doublequote (") | \" |
beep (audible beep sound) | \a |