package
0.0.0-20240402023223-5f8e0e377ad7
Repository: https://github.com/ch-arham/golang.git
Documentation: pkg.go.dev

# README

Pointers

Pointers hold the memory address of a value.

The * syntax defines a pointer:

var p *int

A pointer's zero value is nil

The & operator generates a pointer to its operand.

myString := "hello"
myStringPtr = &myString

The * dereferences a pointer to gain access to the value

fmt.Println(*myStringPtr) // read myString through the pointer
*myStringPtr = "world"    // set myString through the pointer 

Unlike C, Go has no pointer arithmetic

Just because you can doesn't mean you should

We're doing this exercise to understand that pointers can be used in this way. That said, pointers can be very dangerous. It's generally a better idea to have your functions accept non-pointers and return new values rather than mutating pointer inputs.

Assignment

Complete the removeProfanity function.

It should use the strings.ReplaceAll function to replace all instances of the following words in the input message with asterisks.

  • "dang" -> "****"
  • "shoot" -> "*****"
  • "heck" -> "****"

It should mutate the value in the pointer and return nothing.

Do not alter the function signature.