Logo

Programming-Idioms

History of Idiom 163 > diff from v21 to v22

Edit summary for version 22 by cdo:
New C implementation by user [cdo]

Version 21

2020-04-28, 20:56:54

Version 22

2020-04-28, 21:44:46

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Imports
#include <stdio.h>
Code
for (unsigned i = 0; i < sizeof(list) / sizeof(list[0]); i += 2)
	printf("%d, %d\n", list[i], list[i + 1]);
Comments bubble
I'm treating list as an array not a list because C doesn't have lists built in.
The length had better be even or there'll be undefined behaviour to pay!