diff --git a/lesson2/25_B_return_pointer.c b/lesson2/25_B_return_pointer.c index cb24896..29452c4 100644 --- a/lesson2/25_B_return_pointer.c +++ b/lesson2/25_B_return_pointer.c @@ -1,10 +1,19 @@ #include +// WARNING: The get_pointer() function below contains UNDEFINED BEHAVIOR in C. +// It returns a pointer to a local variable that is destroyed when the function exits. +// This example is intentionally shown to demonstrate how Go differs from C: +// Go handles this safely using automatic memory management, +// while C results in undefined behavior if the pointer is dereferenced. + int* get_pointer(void) { int i = 42; return &i; } +// Note: Running this program may appear to work on some systems due to +// undefined behavior, but it can crash or produce garbage output. + int main(void) { int *p = get_pointer(); printf("%p\n", p);