Is My Array Looping Method in C a Good Practice?

0
2
Asked By CodingWhiz42 On

I've been using a method to loop through an array in C that involves a pointer and decrementing the size variable. My loop looks like this: for (; a < a + n; a++, n--) where 'a' points to the first element of the array (or a row in a multidimensional array), and 'n' is the size of that row or the entire array. I'm curious about whether this method is safe and if using subscripting might be a better approach.

2 Answers

Answered By SyntaxSavant On

Honestly, I'm not a fan of this approach. It can make the code harder to read since it replaces a common looping structure with something that might confuse readers. Code should be as clear as possible!

LogicLover99 -

Totally agree! Clever tricks can often lead to unmaintainable code.

Answered By CodeCrafter101 On

I think readability should come first, so I don't see this as an improvement. There's nothing wrong with the traditional way of looping. That said, it’s cool to experiment with different methods!

TechieTim -

Do you think this method has any performance benefits?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.