mirror of
https://git.aramjonghu.dev/AramJonghu/ziglings.git
synced 2026-09-06 10:13:29 +02:00
pointers exercises done
This commit is contained in:
@@ -31,7 +31,7 @@ pub fn main() void {
|
|||||||
|
|
||||||
// Please define pointer "p" so that it can point to EITHER foo or
|
// Please define pointer "p" so that it can point to EITHER foo or
|
||||||
// bar AND change the value it points to!
|
// bar AND change the value it points to!
|
||||||
??? p: ??? = undefined;
|
var p: *u8 = undefined;
|
||||||
|
|
||||||
p = &foo;
|
p = &foo;
|
||||||
p.* += 1;
|
p.* += 1;
|
||||||
|
|||||||
@@ -37,5 +37,5 @@ pub fn main() void {
|
|||||||
// This function should take a reference to a u8 value and set it
|
// This function should take a reference to a u8 value and set it
|
||||||
// to 5.
|
// to 5.
|
||||||
fn makeFive(x: *u8) void {
|
fn makeFive(x: *u8) void {
|
||||||
??? = 5; // fix me!
|
x.* = 5; // fix me!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ pub fn main() void {
|
|||||||
|
|
||||||
// FIX ME!
|
// FIX ME!
|
||||||
// Please pass Glorp to printCharacter():
|
// Please pass Glorp to printCharacter():
|
||||||
printCharacter(???);
|
printCharacter(&glorp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note how this function's "c" parameter is a pointer to a Character struct.
|
// Note how this function's "c" parameter is a pointer to a Character struct.
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ const Elephant = struct {
|
|||||||
|
|
||||||
pub fn main() void {
|
pub fn main() void {
|
||||||
var elephantA = Elephant{ .letter = 'A' };
|
var elephantA = Elephant{ .letter = 'A' };
|
||||||
|
var elephantB = Elephant{ .letter = 'B' };
|
||||||
// (Please add Elephant B here!)
|
// (Please add Elephant B here!)
|
||||||
var elephantC = Elephant{ .letter = 'C' };
|
var elephantC = Elephant{ .letter = 'C' };
|
||||||
|
|
||||||
// Link the elephants so that each tail "points" to the next elephant.
|
// Link the elephants so that each tail "points" to the next elephant.
|
||||||
// They make a circle: A->B->C->A...
|
// They make a circle: A->B->C->A...
|
||||||
elephantA.tail = &elephantB;
|
elephantA.tail = &elephantB;
|
||||||
|
elephantB.tail = &elephantC;
|
||||||
// (Please link Elephant B's tail to Elephant C here!)
|
// (Please link Elephant B's tail to Elephant C here!)
|
||||||
elephantC.tail = &elephantA;
|
elephantC.tail = &elephantA;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user