Saturday 15 February 2014

Passing structure to function in C -



Passing structure to function in C -

#include<stdio.h> #include<stdlib.h> struct point { int x; int y; }; void get(struct point p) { printf("enter x , y coordinates of point: "); scanf("%d %d",&p.x,&p.y); } void put(struct point p) { printf("(x,y)=(%d,%d)\n",p.x,p.y); } int main () { struct point pt; get(pt); put(pt); homecoming 0; }

i trying write programme x , y coordinates user , them print them out screen. 1 time come in x , y coordinates , go out print them out screen get: (x,y)=(56,0). new working structures help good. give thanks you.

you may homecoming construction straight function, since little structure.

struct point get() { struct point p; printf("enter x , y coordinates of point: "); scanf("%d %d",&p.x,&p.y); homecoming p; } int main () { put(get()); homecoming 0; }

c structure pass-by-value

No comments:

Post a Comment