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 বনাম calloc: calloc memory শূন্যও করে; realloc তার size বদলায়। Stack বনাম heap interview-এর ঘনঘন প্রশ্ন।

Challenge

+35 XP

n পড়ুন, malloc দিয়ে n-টি int-এর array তৈরি করুন, প্রথম n-টি Fibonacci সংখ্যা (0, 1, 1, 2, ...) দিয়ে ভরুন, space দিয়ে আলাদা করে 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.