One of the concepts I love is arrays. I really like putting values inside one container. Feels like cheating and magic at the same time. It can store values and even variables, it can also be one-dimensional or multi-dimensional, and it just solves many problems.
Below is the code for declaring and accessing arrays:
import std.stdio; int main(){ int numbers[4] = [5,1,3,10]; int sum = 0; for(int i = 0; i<numbers.length; i++){ sum+= numbers[i]; } writeln("The sum is ", sum); return 0; }
Here is the output:
I hope you like this post.
Don’t forget to leave a comment.
Thank you very much.