how to put NULL or empty value to an integer array?
struct book{
char name;
char aut;
int det[10];
};
book bk[40];
here i want every book data type to have there det arrays have value zero for every det[] member.
int num[5] = {1, 1, 1, 1, 1}; This will initialize the num array with value 1 at all index. The array will be initialized to 0 in case we provide empty initializer list or just specify 0 in the initializer list. Designated Initializer: This initializer is used when we want to initialize a range with the same value.
Array Initialization Using a Loop The following syntax uses a “for loop” to initialize the array elements. This is the most common way to initialize an array in C. // declare an array. int my_array[5];
I think you mean how to zero-initialize an integer array.:)
You can define the array like
int det[10] = {};
or
int det[10] = { 0 };
You may use such a declaration in a structure.
If the array is already defined then you can use memset. For example
#include <cstring>
//...
std::memset( det, 0, sizeof( det ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With