On this page
Syntax, Types & Operators
Prev: fundamentals | Up: fundamentals | Next: Control Flow & Functions
Rel: stdint, stdbool & limits, Binary & Encodings
Ref: cppreference — C Types
Tags: #public #prog #c #fundamentals
Contents
Minimal Standard C Program
#include <stdint.h>
#include <stdio.h>
int main(void) {
int32_t count = 42;
printf("count = %d, sizeof(size_t) = %zu\n", count, sizeof(size_t));
return 0;
}
Compile with strict warnings: cc -std=c17 -Wall -Wextra -Werror main.c -o main.
Fundamental Types, sizeof & Bitwise Operators
- Prefer
<stdint.h>exact-width types (int32_t,uint64_t) andsize_tfor sizes/indices rather than assuminglongis 64-bit across platforms. sizeofis a compile-time operator returningsize_t(bytes).- Bitwise operators (
&,|,^,~,<<,>>) should always be applied to unsigned integers (uint32_t) to avoid signed-shift undefined behavior.
uint32_t flags = 0;
const uint32_t READ = 1u << 0;
const uint32_t WRITE = 1u << 1;
flags |= READ | WRITE; // set bits
flags &= ~WRITE; // clear WRITE bit
Linked from
Related notes
- tuts/c/fundamentals Linked here; links to this page; shared tags: #c, #fundamentals, #prog
- tuts/c/fundamentals/control_flow_and_functions Linked here; links to this page; shared tags: #c, #fundamentals, #prog
- tuts/c/stdlib/stdint_stdbool_and_limits Linked here; links to this page; shared tags: #c, #prog
- tuts/c/builtins links to this page; shared tags: #c, #prog
- tuts/programming/data_and_types/binary_numbers_and_encodings Linked here; shared tags: #prog
- tuts/c/fundamentals/arrays_and_strings shared tags: #c, #fundamentals, #prog
- tuts/c/fundamentals/structs_unions_and_enums shared tags: #c, #fundamentals, #prog
- tuts/c shared tags: #c, #prog
- tuts/c/builtins/__FILE__ shared tags: #c, #prog
- tuts/c/builtins/__func__ shared tags: #c, #prog