C++ | கணினி அறிவியல் - பயனர் வரையறுத்த செயற்கூற்றுகளை அறிவிக்கும் போது பயன்படுத்தப்படும் பல்வேறு வடிவங்கள் | 11th Computer Science : Chapter 11 : Functions
பயனர் வரையறுத்த செயற்கூற்றுகளை அறிவிக்கும் போது பயன்படுத்தப்படும் பல்வேறு வடிவங்கள்
1. மதிப்பை திருப்பி அனுப்பாத மற்றும் அளபுருக்களை ஏற்காத செயற்கூறு
கீழே கொடுக்கப்பட்டுள்ள நிரல் மதிப்பைத் திருப்பி அனுப்பாத மற்றும் அளபுருக்களை ஏற்காத செயற்கூறிற்கான ஒரு எடுத்துக்காட்டு.
display() என்பது செயற்கூறின் பெயர், இதன் திருப்பி அனுப்பும் தரவினம் void மற்றும் இந்த செயற்கூறு எந்த அளபுருவையும் ஏற்காது.
நிரல் 11.20
#include<iostream>
using namespace std;
void display()
{
cout<<"First C++ Program with Function";
}
int main()
{
display(); // Function calling statement//
return(0);
}
வெளியீடு :
First C++ Program with Function
2. திருப்பி அனுப்பும் மதிப்பு மற்றும் அளபுருக்களை ஏற்காத செயற்கூறு
display() என்ற செயற்கூறின் திருப்பி அனுப்பும் தரவினம் int மற்றும் இந்த செயற்கூறு அளபுருவையும் ஏற்காது. return செயற்கூறு அழைப்பு செயற்கூறுக்கு மதிப்பைத் திருப்பி அனுப்பும் மற்றும் நிரலின் கட்டுப்பாட்டை மீண்டும் அழைப்புக் கூற்றுக்கு திருப்பி அனுப்பும்.
நிரல் 11.21
#include<iostream>
using namespace std;
int display()
{
int a, b, s;
cout<<"Enter 2 numbers: ";
cin>>a>>b;
s=a+b;
return s;
}
int main()
{
int m=display();
cout<<"\nThe Sum="<<m;
return(0);
}
வெளியீடு :
Enter 2 numbers: 10 30
The Sum=40
3. மதிப்பை திருப்பி அனுப்பாத மற்றும் அளபுருக்களை ஏற்கும் செயற்கூறு
display() என்ற செயற்கூறின் திருப்பி அனுப்பும் தரவினம் void, மேலும் இது x மற்றும் y என்ற இரண்டு அளபுருக்கள் அல்லது செயலுருபுக்களின் மதிப்புகளை ஏற்கும். return கூற்று கட்டுப்பாட்டை அழைப்பு கூற்றுக்குத் திருப்பி அனுப்பும்.
நிரல் 11.22
#include<iostream>
using namespace std;
void display(int x, int y)
{
int s=x+y;
cout<<"The Sum of Passed Values: "<<s;
}
int main()
{
int a,b;
cout<<"\nEnter the First Number :";
cin>>a;
cout<<"\nEnter the Second Number :";
cin>>b;
display(a,b);
return(0);
}
வெளியீடு :
Enter the First Number :50
Enter the Second Number :45
The Sum of Passed Values: 95
4. மதிப்பை திருப்பி அனுப்பும் மற்றும் அளபுருவை ஏற்கும் செயற்கூறு
display(), என்ற செயற்கூறு int என்ற மதிப்பைத் திருப்பி அனுப்பும். மேலும் x மற்றும் y என்ற இரண்டு அளபுருக்கள் அல்லது செயலுருபுக்களில் மதிப்புகளை ஏற்கும். return கூற்று கட்டுப்பாட்டை அழைப்பு கூற்றிக்குத் திருப்பி அனுப்பும்.
நிரல் 11.23
#include<iostream>
using namespace std;
int display(int x, int y)
{
int s=x+y;
return s;
}
int main()
{
int a,b;
cout<<"\nEnter the First Number :";
cin>>a;
cout<<"\nEnter the Second Number :";
cin>>b;
int s=display(a,b);
cout<<”\nExample:Function with Return Value and with Arguments”;
cout<<"\nThe Sum of Passed Values: "<<s; return(0);
}
வெளியீடு :
Enter the First Number :45
Enter the Second Number :67
Example: Function with Return Value and with Arguments
The Sum of Passed Values: 112