7.1 INTRODUCTION

৭.১ পৰিচয়

We have seen that when we need to do many tasks in a program, the length of the program increases. Sometimes, it becomes difficult to read and understand that. There is an interesting construct in computer programming that handles this issue nicely called function!

আমি দেখিছোঁ যে যেতিয়া আমি এটা কাৰ্যসূচীত বহুতো কাম কৰাৰ প্ৰয়োজন হয়, প্ৰ’গ্ৰামটোৰ দৈৰ্ঘ্য বৃদ্ধি হয়। কেতিয়াবা, সেইটো পঢ়া আৰু বুজিপোৱা কঠিন হৈ পৰে। কম্পিউটাৰ প্ৰ’গ্ৰামিংত এটা আকৰ্ষণীয় নিৰ্মাণ আছে যিয়ে এই সমস্যাটো সুন্দৰভাৱে পৰিচালনা কৰে যাক ফাংচন বুলি কোৱা হয়।

Moreover, if we need to perform a task many times, we typically need to write the code that many times. But if we create a function and put the statements there, we just need to write only once. In that case, everytime we need to perform the task, we can simply make a call to the function and we are done.

তদুপৰি, যদি আমি বহুবাৰ কাম এটা সম্পাদন কৰাৰ প্ৰয়োজন হয়, আমি সাধাৰণতে বহুবাৰ কোডটো লিখিব লাগিব। কিন্তু যদি আমি এটা ফাংচন সৃষ্টি কৰোঁ আৰু বিবৃতিবোৰ তাত ৰাখোঁ, আমি কেৱল এবাৰহে লিখিব লাগিব। তেনে ক্ষেত্ৰত, যেতিয়াই আমি কামটো সম্পাদন কৰিব লাগিব, আমি কেৱল ফাংচনটোলৈ ফোন কৰিব পাৰোঁ আৰু আমি সম্পূৰ্ণ হ’ম।

A function in computer programming is a group of statements that together perform a task. We can divide our code of a program into separate functions. How we divide the code among different functions is up to us, but logically the division is such that each function performs a specific task.

কম্পিউটাৰ প্ৰ’গ্ৰামিংত এটা ফাংচন হৈছে বিবৃতিৰ এটা গোট যি একেলগে এটা কাম কৰে। আমি প্ৰ’গ্ৰাম এটাৰ আমাৰ কোডক পৃথক ফাংচনলৈ বিভক্ত কৰিব পাৰোঁ। আমি কোডটো বিভিন্ন ফাংচনৰ মাজত কেনেদৰে বিভাজন কৰোঁ সেয়া আমাৰ ওপৰত নিৰ্ভৰ কৰে, কিন্তু যুক্তিসঙ্গতভাৱে বিভাজন টো এনেকুৱা যে প্ৰতিটো ফাংচনে এটা নিৰ্দিষ্ট কাম কৰে।

There are some common terminologies with respect to functions in C. Let us first understand these.

চি-ত কাৰ্যৰ সন্দৰ্ভত কিছুমান উমৈহতীয়া পৰিভাষা আছে। প্ৰথমে আমি এইবোৰ বুজি পাওঁ আহক।

Function name: Every function has to be given a valid name. Any valid identifier except the keywords can be a function name in C.

ফাংচন নাম: প্ৰতিটো ফাংচনক এটা বৈধ নাম দিব লাগিব। কীৱৰ্ডৰ বাহিৰে যিকোনো বৈধ চিনাক্তকৰ্তা চি-ত এটা ফাংচন নাম হ’ব পাৰে।

Return type: Every function in Causally returns a value. The data type of the returning value becomes the return type of the function. For example, if we return an integer from a function, the return type of the function becomes int. In case a function does not return anything. its return type becomes void. A function can return only one item.

ৰিটাৰ্ণ প্ৰকাৰ: কাৰকৰ প্ৰতিটো ফাংচনে এটা মূল্য ঘূৰাই দিয়ে। ৰিটাৰ্ণিং মানৰ ডাটা প্ৰকাৰ ফাংচনৰ ৰিটাৰ্ণ প্ৰকাৰ হৈ পৰে। উদাহৰণ স্বৰূপে, যদি আমি ফাংচন এটাৰ পৰা ইণ্টেগাৰ এটা ঘূৰাই দিওঁ, ফাংচনৰ ৰিটাৰ্ণ প্ৰকাৰ টো ইণ্ট হৈ পৰে। যদি ফাংচন এটাই একো ঘূৰাই নিদিয়ে। ইয়াৰ ঘূৰি অহাৰ প্ৰকাৰ শূন্য হৈ পৰে। ফাংচন এটাই কেৱল এটা আইটেম ঘূৰাই দিব পাৰে।

Function parameter: We can pass or send some data to a function when it is executed. Parameters in a function refer to these data. Parameters are like placeholders; they take some data along with them as input.

ফাংচন প্ৰাচল: আমি ফাংচন এটা কাৰ্যসম্পাদন কৰাৰ সময়ত কিছুমান ডাটা পাছ বা প্ৰেৰণ কৰিব পাৰোঁ। ফাংচন এটাৰ প্ৰাচলবোৰে এই ডাটাবোৰ বুজায়। প্ৰাচলবোৰ স্থানধাৰকৰ দৰে; তেওঁলোকে তেওঁলোকৰ সৈতে কিছু তথ্য ইনপুট হিচাপে লয়।

The above code segment indicates a function whose name is “calculate_interest”. The return type of the function is “float” and the function has three parameters – “principal amount”, “year” and “rate_of_interest”.

ওপৰোক্ত কোড খণ্ডটোৱে এটা ফাংচন সূচায় যাৰ নাম “calculate_interest”। ফাংচনটোৰ ৰিটাৰ্ণ প্ৰকাৰহৈছে “ফ্লোট” আৰু ফাংচনটোৰ তিনিটা প্ৰাচল আছে – “মূল পৰিমাণ”, “বছৰ” আৰু “rate_of_interest”।

Parameters of a function are also termed as arguments. A function in C may not accept any parameter. We call such functions as 0-argument functions.

ফাংচন এটাৰ প্ৰাচলবোৰক তৰ্ক বুলিও কোৱা হয়। চি-ত এটা ফাংচনে কোনো প্ৰাচল গ্ৰহণ নকৰিবপাৰে। আমি এনে ফাংচনবোৰক 0-তৰ্ক ফাংচন বুলি কওঁ।