Small program
Read arguments, parse a number and print a result.
What you will be able to do
- Use std.process.argsAlloc.
- Handle parse errors.
- Free allocated data.
In plain English
Read arguments, parse a number and print a result.
- Use std.process.argsAlloc.
- Handle parse errors.
- Free allocated data.
const std = @import("std");
pub fn main() !void {
const allocator = std.heap.page_allocator;
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);
const n = std.fmt.parseInt(u32, args[1], 10) catch 0;
std.debug.print("{d}\n", .{n * 2});
}Your turn
EasyExplain it back
Answer from memory: Which function reads process arguments?
TEXT · starter
Your answer…Check your understanding before moving on.
Knowledge checkQuestion 1
Which function reads process arguments?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.