Passing Arguments to Functions of Structure in C programming to combine different data types to store a particular type of record. It helps to construct a complex data type in a more meaningful way.
#include<stdio.h>
#include<conio.h>
struct str //'str' is name of Structure.
{
void fun() //this is function.
{
printf("This is Simple Function\n");
}
void fun2(int a, int b, char c) //passing arguments here to parameters.
{ //and printing.
printf("1st Value: %d\n2nd Value: %d\n3rd Value: %c", a, b, c);
}
};
void main()
{
str obj; //'obj' is object of Structure 'str'.
obj.fun(); //calling 'fun()' function.
obj.fun2(123, 415, 'A'); //calling and passing arguments to parameters.
getch();
}
#include<stdio.h>
#include<conio.h>
struct str //'str' is name of Structure.
{ //this is function and passing here Arguments to parameters.
void fun(char *name, int roll, char sec)
{ //and printing.
printf("Name is: %s\nRoll Number is: %d\nSection is: %c\n", name, roll, sec);
}
};
void main()
{
str obj; //'obj' is object of Structure 'str'.
obj.fun("HiLaLs", 120122067, 'B'); //passing arguments to parameters.
obj.fun("Haq Nawaz", 1201220, 'A'); //passing again arguments to parameters.
getch();
}
#include<stdio.h>
#include<conio.h>
struct str //'str' is name of Structure.
{
char *name; //'name' is for pointer value.
int roll;
char sec;
void fun() //this is function.
{
printf("Name is: %s\n", name);
printf("Roll No is: %d\n", roll);
printf("Section is: %c\n", sec);
}
};
void main()
{
str obj; //'obj' is object of Structure 'str'.
obj.name = "HiLaLs"; //with the help of object 'obj'
obj.roll = 120122067; //assigning values to 'name', 'roll'
obj.sec = 'B'; //and 'sec'.
obj.fun(); //and calling 'fun()' function.
getch();
}