Erik Fredericks, frederer@gvsu.edu Fall 2025
Based on material provided by Erin Carrier, Austin Ferguson, and Katherine Bowers
Non-floating point
int
long
long long
Floating point
float
double
Character
char
true/false?
true
false
https://stackoverflow.com/questions/1921539/using-boolean-values-in-c
Pre C-99 - no boolean type!
ints
https://stackoverflow.com/questions/36662063/how-can-i-know-the-version-of-c
gcc -dM -E - < /dev/null | grep __STDC_VERSION__ | awk '{ print $2 " --> " $3 }'
__STDC_VERSION__ --> 201710L
c89
c99
c11
c17
#include <stdio.h> #include <stdbool.h> // need the boolean header! int main(void) { bool var; var = true; printf("Boolean value: %d\n", var); printf("Boolean value as str: %s\n", var ? "true" : "false"); return 0; }
printf(controlstring [, data])
controlstring
data
integer: %d (you may see %i)
%d
%i
d
%3d
%03d
%-3d
float/double: %f, %e, %g
%f
%e
%g
Number before decimal - total width to use
Number after decimal - places after decimal point
Use 0 for 0-fill, use - for left justify
0
-
We can still further customize: printf("PI = %08.3f", 3.14);
printf("PI = %08.3f", 3.14);
Here:
8
3
Character: %c
%c
String: %s
%s
These are different:
int x = 5;
unsigned int y = 5;
Why would we ever use unsigned ints?
C will automatically convert types in certain scenarios:
Operating on mismatched types
3.0 / 2
Assigning values
double x = 5;
int y = 4.0;
Calling functions
float_exp(2, 3);
We can also typecast!
int x = (int) 5.0;
(unsigned int) -1;
Format: (type) expression;
(type) expression;
signed 16 bits - max number is 2^16-1 = 32767 unsigned - 65,535
8 bits to a byte 4 bits to a nibble 8 bit int: -128-127 16 bit: -32768 - 32,767