You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
975 B
C
37 lines
975 B
C
#include <stdio.h>
|
|
|
|
//Type definition
|
|
typedef unsigned char byte;
|
|
|
|
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
int i = 123;
|
|
float f = 1.23f;
|
|
double d = 2.34;
|
|
char c = 'c';
|
|
|
|
//variations
|
|
unsigned int ui = 123u;
|
|
|
|
//short and long provide different storage depending on the compiler and platform
|
|
//Regular int usually maps to the natural size of a word on a particular machine
|
|
// Ex: on a 32 bit machine int == 32 bits short == 16 bits and long == 64 bits ...or 32
|
|
short int si = 123;
|
|
long int li = 123;
|
|
|
|
//short hand declaration of short and long
|
|
short sh_si = 123;
|
|
long sh_li = 123;
|
|
|
|
//typedef example
|
|
byte b = 0x12;
|
|
|
|
//we have to cast the result of sizeof because it returns a value whose size is large enough
|
|
//to hold a pointer value, but the fundamental types will never be that big so we cast
|
|
printf("The value of i: %d (%d) bytes\n", i, (int) sizeof(int));
|
|
//this will tell us that int is 4 bytes and running in a 32 bit address space
|
|
|
|
return 0;
|
|
} |