Declaration of a global array of C structures

Asked

Viewed 208 times

1

I created a structure cliente and the next idea would be to create a array clientes. My idea would be to declare array clientes globally, so that all functions can interact without passing it as an input parameter. But since I’m such a beginner I don’t know if it’s good practice.

  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).

2 answers

1

In general no, the correct thing is to pass everything as a parameter, everything that is global ends up being lost in the organization. Of course, for something simple will not give problem and can give the false sense of security, but when it starts making real codes becomes complicated, so learn to do the right way from the beginning. This is independent of your problem. It is rare to need something global and you need to have a good command of programming to use properly. When in doubt use parameters.

1


Since you are a beginner I think it is best to use the same parameter, you can get lost to control this global variable. Another tip that I give, research on "structures"(struct) is a simple way to understand and I think it is more organized. 'Cause you can define well without having to worry too much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.