How to initialize a struct to zero or null in C

1 Answer

0 votes
#include <stdio.h>
 
typedef struct {
    char name[32];
    int age;
    float salary;
} USER;
 
int main(void) {
 
    static const USER user;
 
    printf("user.name : %s\n", user.name);
    printf("user.age : %d\n", user.age);
    printf("user.salary : %.2f\n", user.salary);
 
    return 0;
}
 
 
 
 
/*
run:
 
user.name :
user.age : 0
user.salary : 0.00
 
*/

 



answered May 19, 2022 by avibootz
edited Apr 24, 2023 by avibootz

Related questions

2 answers 108 views
1 answer 90 views
90 views asked May 19, 2022 by avibootz
1 answer 131 views
...