How to create and initialize one object from a struct in C++

1 Answer

0 votes
#include <iostream>

struct Example {
    int n;
    float f;
    char ch;
};

int main() {
    Example obj = {145, 0.389f, 'z'}; 
    
    std::cout << obj.n << " " << obj.f << " " << obj.ch; 
}


/*
run:

145 0.389 z

*/

 



answered Dec 31, 2024 by avibootz

Related questions

1 answer 151 views
1 answer 174 views
1 answer 199 views
199 views asked Mar 7, 2020 by avibootz
1 answer 179 views
...