Pass structure as an argument to a function - C Structure

C examples for Structure:Structure Value

Introduction

When passing structure to a function, the structure is passed using the normal call-by-value method.

Any changes made to the contents of the parameter inside the function do not affect the structure passed as the argument.

The type of the argument must match the type of the parameter.

Demo Code

#include <stdio.h>

struct struct_type {
   int a, b;//from ww  w.j a v  a 2  s .c o  m
   char ch;
};

void f1(struct struct_type parm);

int main(void)
{
   struct struct_type arg;

   arg.a = 1000;

   f1(arg);

   return 0;
}

void f1(struct struct_type parm)
{
   printf("%d", parm.a);
}

Result


Related Tutorials