Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

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 237 views
1 answer 192 views
192 views asked Jun 12, 2015 by avibootz
2 answers 152 views
1 answer 135 views
2 answers 272 views
1 answer 270 views
270 views asked Jun 11, 2015 by avibootz
1 answer 306 views
...