const para valores que nunca mudam
Vinculações imutáveis por padrão.
const para valores que nunca mudam é 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.
Bindings Start Here
In Zig, you give a value a name with a binding. The first choice you make is whether that name is allowed to change later.
Meet const
The keyword const creates a name whose value can never be reassigned. It is the safe, default way to name things in Zig.
const pi = 3.14159;Immutable by Choice
A const binding is immutable: once it points at a value, that link is locked. This makes your code easier to read and reason about.
Reassigning Is an Error
Try to give a const a new value and the compiler stops you. Zig reports a clear error instead of silently letting the bug through.
const x = 5;
x = 6; // error: cannot assign to constantInitialize at Declaration
You set a const's value right where you declare it. There is no empty const waiting to be filled in later on.
const greeting = "Hello, Zig";const for Configuration
Fixed numbers like a buffer size or a max count are perfect for const. They name a value clearly and guarantee it stays put.
const max_users = 100;Prefer const First
Good Zig style reaches for const first and only loosens up when a value truly must change. Less mutation means fewer surprises.
Type Is Still Inferred
You usually do not write a type after const. Zig infers it from the value, so const count = 0 just works as an integer.
const count = 0;const at the Top Level
Constants declared outside any function become file-wide globals. They are evaluated once and shared across your whole program.
const version = "1.0.0";Importing Returns a const
You will often see const std = @import. The result of an import is a value, and binding it with const keeps that module fixed.
const std = @import("std");Self-Documenting Code
Seeing const tells any reader the value will not move. That single keyword acts as a small, trustworthy promise about your intent.
Quick Check
You declare const limit = 10. What happens if you later write limit = 20?
Recap
You learned that const names a value that never changes. Initialize it once, let Zig infer the type, and reach for it as your default. 🔒
Perguntas Frequentes
A aula “const para valores que nunca mudam” é grátis?
Sim — o texto completo de “const para valores que nunca mudam” é 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 “const para valores que nunca mudam”?
Vinculações imutáveis por padrão. 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 “const para valores que nunca mudam”?
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
- const para valores que nunca mudam
- var para estados mutáveis
- Inferência de tipos versus tipos explícitos
- undefined e memória não inicializada