
A variable is a named box in memory. In VisuAlg every box has a type, and the type decides what you can store in it. Getting types right early prevents most of the "type incompatible" errors new students meet.
The four primitive types
| Type | Stores | Example |
|---|---|---|
inteiro | Whole numbers, positive or negative | idade <- 19 |
real | Numbers with decimals | altura <- 1.75 |
caractere | Text of any length | nome <- "Ana" |
logico | VERDADEIRO or FALSO | ativo <- VERDADEIRO |
Note that decimal numbers use a dot, not a comma: write 1.75, never 1,75.
Declaring variables
var
idade, ano: inteiro
altura, peso: real
nome: caractere
matriculado: logico
You can declare several variables of the same type on one line, separated by commas. All declarations live in the var section, before inicio.
Naming rules
- Start with a letter or underscore.
- Use only letters, digits and underscores; no spaces or accents.
- Do not use reserved words such as
se,paraorinicio. - VisuAlg is not case-sensitive, so
Notaandnotaare the same variable.
Mixing types in expressions
You can assign an inteiro to a real variable, but not the reverse. Division with / always produces a real result, so storing it in an inteiro causes an error. When you need whole-number division, use \, and use % (or mod) for the remainder.
algoritmo "divisao"
var
a, b, q, r: inteiro
media: real
inicio
a <- 17
b <- 5
q <- a \ b // 3
r <- a % b // 2
media <- a / b // 3.4
escreval(q, " ", r, " ", media)
fimalgoritmo
Logical values in practice
Logical variables shine when you store the result of a comparison: aprovado <- nota >= 7. You can then test se aprovado entao later, which keeps conditions readable.
Converting between types
Built-in functions help when you need to switch types: int(x) drops the decimals of a real, numpcarac(n) turns a number into text and caracpnum(t) turns text into a number.
Now put your variables to work with conditional statements.


