RedHatOfficial / RedHatOfficial/GoCourse
lesson2/25_B_return_pointer.c: misleading C example for pointer semantics
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 737
- Forks
- 158
- PR merge metrics
- No merged PRs in 30d
Description
on slide 61 of lesson 2 (sub-theme Pointers), an example C code snippet is presented to illustrate pointer behavior, specifically returning the address of a local variable
int* get_pointer(void) {
int i = 42;
return &i;
}
the slide then juxtaposes this with a Go equivalent, implying similar behavior or direct analogy:
func getPointer() *int {
var i int = 42
return &i
}
the C code example for get_pointer() that returns the address of a stack-allocated variable int i immediately leads to Undefined Behavior upon dereferencing the returned pointer in main printf("%d\n", *p);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open lesson2/25_B_return_pointer.c and inspect slide 61 in the Pointers section, then compare the C and Go examples and their surrounding explanation. Verify the C behavior involving the returned local-variable address and revise the example or wording so the comparison is accurate and no longer implies equivalent pointer semantics. Done when the slide accurately describes both snippets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, go
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100