How to use value initialization to guarantee that struct values are zero and empty string in C++

1 Answer

0 votes
#include <iostream>
 
struct ST {
    int first, second, third;
    std::string str;
} typedef ST;
  
int main() {
    ST st{};
     
    std::cout << st.first << " " << st.second << " " << st.third << '\n';
    std::cout << st.str;
}
  
  
  
  
/*
run:
  
0 0 0
  
*/

 



answered Dec 8, 2023 by avibootz
...