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 337 views
1 answer 177 views
1 answer 215 views
1 answer 164 views
2 answers 313 views
2 answers 291 views
291 views asked Jun 13, 2015 by avibootz
3 answers 227 views
227 views asked May 14, 2021 by avibootz
...