C Parameterized Function In Hindi

📔 : C 🔗

पिछले topic में पढ़ा कि C में Function कैसे define करते हैं , और कैसे call / invoke करते हैं , but वो simple functions थे जो सिर्फ static result generate / return करते थे , इस topic में हम Parameterized Function के बारे में पड़ेंगे जिससे हम dynamic value return करा सकें।


Parameterized Function वो function होते हैं जो कि parameter accept करते हैं , इन functions को define करते समय हम parameter भी define करते हैं जो कि ensure करते हैं कि call करते समय हम कितने argument pass करने वाले हैं। हालाँकि parameter define करते समय आपको parameter type भी define करने पड़ेगा , जिससे ये ये पता चले कि किस type की value function में pass होगी।

C Parameterized Function Syntax

type function function_name(type param1, type param2)
{
  // your logic
  return value; //according to function type
}

function में हम अपनी need के according कितने ही parameter pass कर सकते हैं। और यही parameter उस function के लिए as a variable work करते हैं।

ध्यान रहे कि pass किये गये arguments / values , function में define किये गए parameters के बराबर ही होनी चाहिए।

C Parameterized Function Example

CopyFullscreenClose FullscreenRun
#include <stdio.h>
// define the function that returns nothing.
void print_sum(int num1, int num2){
  printf("Sum : %i \n", num1+num2);
}

int main() { 
  // call the function by passing arguments.
  print_sum(12,23);
  
  //call again with different arguments.
  print_sum(10, 20);
  print_sum(30, 120);
  print_sum(50, 40);
  print_sum(110, 20);
  print_sum(30, 10);
  return 0;
}
Output
Sum : 35 
Sum : 30 
Sum : 150 
Sum : 90 
Sum : 130 
Sum : 40 

Example में जैसा कि आप देख सकते हैं कि , same function को different arguments के साथ call / invoke किया गया है और different output return किया है , और यही function का main advantage है आपको , same instruction / process के लिए बार बार code नहीं करना पड़ता है।

? Technically देखा जाए तो किसी function के लिए Parameter और Argument दोनों अलग अलग हैं। Parameters function definition के समय define किये गए variables होते हैं , जबकि function call करते समय pass की गयी values / variables Arguments होते हैं।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers