Write program in Program notebook ...................

 

For Example : Write a program to create samp structure and accept x and y  value and update x variable in function

#include <stdio.h>

#include<conio.h>

struct samp                 //Here samp  is name of structure

{

int x;  //member

int y;

};

void uf(struct samp *p);            //Here p is the pointer variable of structure, p is point to s structure variable

void main()

{

struct samp s;        // Here s a structure variable

printf("\n Enter value for x:");

scanf("%d", &s.x);

printf("\n Enter value for y:");

scanf("%d", &s.y);

uf(&s);    // Here function call

printf("\n Value of x is:%d",s.x);

getch();

}

void uf(struct samp *p)   //Function definition

{

printf("\n Value of X is : %d",p->x);

printf("\n value of y is : %d",p->y);

p->x=100; //assigned 100 value to x (x is updated because the reference is passed)

}

output :





Comments

Popular posts from this blog

Write a program in Program Notebook......