Passing Arguments to Functions of Structure and using the Return keyword in C programming to calculate to passed arguments values and return the result value.
#include<stdio.h>
#include<conio.h>
struct str //'str' is name of Structure.
{ //this is function which Return type is Integer and
int fun(int a, int b) //passing here arguments.
{
int c = a + b; //adding 'a' and 'b' values and assigning to 'c'.
return c; //Returning 'c' value, U also write like 'return (c);'.
}
};
void main()
{
str obj; //'obj' is object of Structure 'str'.
//calling and passing arguments to parameters and printing
printf("Return Value is: %d", obj.fun(6, 5)); //Return values.
getch();
}
#include<stdio.h>
#include<conio.h>
struct str //'str' is name of Structure.
{
str() //this is default constructor.
{
printf("This is Default Constructor\n");
}
void fun() //this is function.
{
printf("This is Simple Function");
}
};
void main()
{ //'obj' is object of Structure 'str' and calling
str obj; //default constructor.
obj.fun(); //calling 'fun()' function.
getch();
}
#include<stdio.h>
#include<conio.h>
struct str //'str' is name of Structure.
{
str() //this is default constructor.
{
printf("This is Default Constructor\n");
}
str(char *p) //this is parameterized constructor and passing
{ //here argument.
printf("This is %s Constructor\n", p);
}
str(int roll, char sec) //this is parameterized constructor and
{ //passing here arguments.
printf("Roll No is: %d\nSection is: %c", roll, sec);
}
};
void main()
{ //'obj', 'obj2' and 'obj3' is objects of Structure 'str'.
str obj; //calling default constructor.
str obj2("Parameterized"); //calling and passing argument to parameter.
str obj3(120122067, 'B'); //calling and passing arguments to parameters.
getch();
}