How to define set value and return struct from function in C

1 Answer

0 votes
#include <stdio.h>
 
struct point 
{ 
    int x; 
    int y; 
};
 
struct point createpoint(int x, int y);

int main(void)
{
    struct point p1; 
    
    p1 = createpoint(13, 7);

    printf("p1.x = %d p1.y = %d", p1.x, p1.y);
    
    return 0;
}

struct point createpoint(int x, int y) 
{ 
    struct point p; 

    p.x = x; 
    p.y = y; 

    return p; 
} 

/*
run:
 
p1.x = 13 p1.y = 7

*/

 



answered Nov 27, 2015 by avibootz

Related questions

1 answer 343 views
1 answer 185 views
1 answer 218 views
1 answer 166 views
2 answers 315 views
2 answers 296 views
296 views asked Jun 13, 2015 by avibootz
3 answers 233 views
233 views asked May 14, 2021 by avibootz
...