functions and function prototyping in c++
#include<iostream>
using namespace std;
// int sum(int a, int b){
// int c = a+b;
// return c;
// }
/**********FUNCTION PROTOTYPE************* */
int sum(int a, int b); //ab program run hojaega
void greet(void);
// void greet();---> acceptable hai
//ye assurity deta hai ki sum function aage hai
//int sum(int a, int b);--->acceptable
//int sum(a, b);---> not acceptable
//int sum(int, int);--->acceptable
int main() {
//compiler main function se read krna start krta code ko.
/*************FUNCTION*************/
/*main is itself a function and yaha return zero ka mtlb hai ki
ye program successfully execute hogya ha and koi dikkat nhi aai hai*/
int k;
int s;
cout<<"enter the value of k "<<endl;
cin>>k;
cout<<"enter the value of s "<<endl;
cin>>s;
cout<<"the value of sum is "<<sum(k,s)<<endl;
/**********FORMAL AND ACTUAL PARAMETERS********* */
/*k and s are actual parameter and formal parameters a and b will be taking value from
actual parameters k and s*/
//formal parameters aur actual parameters same bi ho skte hain
/*jese hi sum ko k and s diya. compiler sum ko dhundega and k aur s ki value a aur b
ko dedega and sum function c ki value return krega which is a+b*/
greet(); //ese run nhi hoga dikhaega greet was not declares so function prototype ka use krna hoga
return 0;
}
int sum(int a, int b){
int c = a+b;
return c;
}
//sum ko baad m likhenge ese to btage sum was not declared, yaha use ata h function prototypes
/*function prototyping btata h pehle se compiler ko ki ye function aane vala hai
so compiler pehle se ready hojata h uss function ko execute krne ke liye*/
void greet(){
cout<<"hello krisha";
}
Comments
Post a Comment