logo
Spark Docs
logo
Spark Docs
DocumentationCore ConceptsVariables

Variables

Learn how to declare, initialize, and manage variables in the C programming language.

Declaring Variables

Spark determines data types automatically based on the assigned value.

# Numbers
let count 42
let price 3.14


# Strings
let text "Hello, World!"


# Booleans
let isTrue true
let isFalse false


# Arrays
let numbers [1, 2, 3, 4, 5]
let names ["Alice", "Bob", "Charlie"]


# Objects
let user { name "Soham" }

Pro Tip: Variable Naming

Use descriptive names like userAgeinstead of a to make your code more readable and maintainable.

Assignment and Reassignment

Values are assigned while declaration or can be reassigned later.

let count

count 0
print count

# Reassign value
count 10
print count

# Change value type
count "ten"
print count

Print with Variables

You can print variables after declaring and assigning them.

let name
let age

name "Alice"
age 25

print name
print age

Combining Strings and Variables

Combine strings and variables using commas.

let firstName
let lastName
let score

firstName "Soham"
lastName "Ganmote"
score 95

print firstName, lastName
print "Your score is", score