Inteiros com tamanho definido: i32, u8, usize
Escolha a largura exata de que precisa.
Inteiros com tamanho definido: i32, u8, usize é uma aula grátis de Zig Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Zig Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Zig Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Integers Carry Their Size
In Zig the width of an integer is part of its type. You always know exactly how many bits a number uses. 🔢
Signed Integers Start with i
A type like i32 is a signed 32-bit integer. The i means it can hold negative values as well as positive ones.
const temperature: i32 = -15;Unsigned Integers Start with u
An u8 is an unsigned 8-bit integer. With no sign bit it stores only non-negative values, from 0 up to 255.
const level: u8 = 200;Pick the Width You Need
The number after i or u is the bit width. A u8 covers 0 to 255, while a u16 reaches all the way up to 65535.
usize for Sizes and Indexes
The usize type is an unsigned integer sized to hold any memory address or index on your machine. Use it for lengths.
const count: usize = 42;isize Is Its Signed Cousin
The isize type matches usize in width but is signed. Reach for it when an index-sized value can also go negative.
Why Explicit Sizes Help
Fixed widths make memory and overflow predictable. You never have to guess how big an int is on a given platform.
Annotate or Let Zig Infer
You can label a value with a type, or let Zig infer it from context. A bare literal often becomes a comptime integer.
const x: i32 = 100;
const y = 7;Values Must Fit the Type
Zig refuses to store a value that does not fit. Assigning 300 to a u8 is a compile error, since u8 stops at 255.
Convert Widths with @intCast
To move between integer widths you ask explicitly. The @intCast built-in converts a value to a different integer type.
const big: u32 = 250;
const small: u8 = @intCast(big);Read the Range in the Name
The name tells you everything: i8 ranges from -128 to 127, while u16 spans 0 to 65535. The width and sign are right there.
Quick Check
You need a value that stores the length of an array or a memory index. Which integer type is the natural fit?
Recap
Zig integers name their sign and width: i32, u8, and usize. Pick the smallest type that fits, and cast on purpose when widths differ. 🎯
Perguntas Frequentes
A aula “Inteiros com tamanho definido: i32, u8, usize” é grátis?
Sim — o texto completo de “Inteiros com tamanho definido: i32, u8, usize” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Zig Academy, atualize para CoddyKit PRO. O curso de Zig Academy inclui 4 aulas no total.
O que vou aprender em “Inteiros com tamanho definido: i32, u8, usize”?
Escolha a largura exata de que precisa. Você pratica Zig Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Zig Academy?
Nenhuma experiência prévia é necessária. Zig Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.
Quanto tempo leva a aula “Inteiros com tamanho definido: i32, u8, usize”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Zig Academy?
Sim. Cada aula de Zig Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Inteiros com tamanho definido: i32, u8, usize
- Ponto flutuante: f32 e f64
- bool, void e os tipos comptime
- Literais numéricos e sublinhados