Initialization of Array in defination

Array can be initialized in definition by normal way as below

int a[5] = { 1, 1, 1, 1, 1};


Another a good way to fill the array with 0 using static

static int a[5]; which fills up the array with 0s
or int a[5] = {0}; fills all elements of the array with 0;

Another very good way to fill the array with different values when using gcc compiler is as below
int a[10] = {[0-2] = 5, [3-9] = 7};
which fills all the array element with 5 and 7s.

for more gcc manual
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Designated-Inits.html

Comments

Popular posts from this blog

Airtel Digital tv remote factory reset and reprogram

Tracking Linux kworker threads

Asynchronus I/O (AIO) in vxworks and Linux