where to declare structures, inside main() or outside main()?

前端 未结 3 1889
春和景丽
春和景丽 2021-02-04 12:39

Case 1: structure declared outside main() working fine

#include
#include
struct prod
{
    int price,         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 13:08

    Structure are a like array only the main difference in Array can hold only same type of values but a structure can have different types of values so if you need to implement structure globally(by globally i mean it can be used in any other function too) define it outside the main and if you want to use your structure only in the main function define it inside it. Happy Coding :-)

提交回复
热议问题