Data typebytes
bool1
int4
long8
float4
double8
char1
string?
  • int

    • whole numbers
    • 4 bytes of memory (32 bits)
    • The range of values they can store is necessarily limited to 31 bits worth of information
      • 2 billion to 2 billion
  • unsigned int

    • unsigned is a qualifier, that can be applied to certain types (including int), which effectively doubles the positive range of variables of that type at the cost of disallowing any negative values
    • 0 to 4 billion
  • char

    • single characters
    • 1 byte of memory (8 bits)
    • We’ve developed a mapping of characters to numeric values using ASCII
    • -128 to 127
  • float

    • used for variables that will store floating-point values - real numbers
    • 4 bytes of memory (32 bits)
    • It has a precision problem
      • ex) look at , it goes on forever - there is a limitation coz we only have 32 bits
  • double

    • variables that will store floating-point values, also known as real numbers
    • 8 bytes of memory (64 bits) - double the precision
      • additional 32 bits from float
  • void

    • is a type but not a data type
    • functions can have a void return type or a void parameter
  • In C, boolean and string are NOT built in!

    • use the #include <cs50.h>

Creating variables

// declaration
int number;
int height;
 
int height, number; // works, but bad practice
 
// assignment
number = 10;
 
// initialization
char letter = 'H';