Lesson 21 of 23

Dynamic Memory: malloc మరియు free

10 min 35 XP

Size run time లో మాత్రమే తెలిసినప్పుడు malloc తో heap memory అడగండి. పని పూర్తయ్యాక free తో విడుదల చేయండి, లేకపోతే memory leak అవుతుంది.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

malloc vs calloc: calloc memory ని సున్నా కూడా చేస్తుంది; realloc దాని size మారుస్తుంది. Stack vs heap తరచుగా వచ్చే interview ప్రశ్న.

Challenge

+35 XP

n చదివి, malloc తో n ints array సృష్టించి, మొదటి n Fibonacci సంఖ్యలతో (0, 1, 1, 2, ...) నింపి, spaces తో print చేసి, తర్వాత free చేయండి. Input: 7 → Output: 0 1 1 2 3 5 8

Output Loading C (first time takes a few seconds)
Press Run to see the result here.