How to define and use global struct in C

2 Answers

0 votes
#include <stdio.h>

struct point 
{
    int x;
    int y;
};

struct point left_point;

int main(int argc, char **argv) 
{ 
    left_point.x = 100;
    left_point.y = 30;
    
    printf("%d\n", left_point.x); // 100
    printf("%d\n", left_point.y); // 30
    
    return(0);
}


/*
run:

100
30

*/

 



answered Jun 13, 2015 by avibootz
0 votes
#include <stdio.h>

struct point 
{
    int x;
    int y;
};

struct point left_point;

void printStruct(struct point p);

int main(int argc, char **argv) 
{ 
    left_point.x = 100;
    left_point.y = 30;
    
    printStruct(left_point);
    
    return(0);
}

void printStruct(struct point p)
{
    printf("%d\n", p.x); 
    printf("%d\n", p.y); 
}

/*
run:

100
30

*/

 



answered Jun 13, 2015 by avibootz

Related questions

1 answer 254 views
1 answer 205 views
205 views asked Jun 12, 2015 by avibootz
2 answers 171 views
1 answer 155 views
2 answers 297 views
1 answer 280 views
280 views asked Jun 11, 2015 by avibootz
1 answer 328 views
...