ELEVATE YOUR BUSINESS WITH

Limitless customization options & Elementor compatibility let anyone create a beautiful website with Valiance.

Arrays in C

SELECT * FROM `itio_tutorial_master` WHERE `tutorial_menu`='28' AND `tutorial_submenu`='1648' AND `tutorial_status`=1 LIMIT 1

Arrays in C

Arrays in C are a powerful way to store multiple values of the same type using a single variable name. You can think of them like boxes lined up in memory — each box holds one item, and you access it by its index.


? Basics of Arrays

? Declaration

c

int numbers[5] = {10, 20, 30, 40, 50};

Or let the compiler count them:

c

int numbers[] = {10, 20, 30};


? Accessing Elements

Indexes start from 0:

c

printf("%d", numbers[0]); // prints 10numbers[1] = 25; // changes second element to 25


? Looping Through an Array

c

#include <stdio.h>int main() { int scores[] = {85, 90, 78, 92, 88}; int length = sizeof(scores) / sizeof(scores[0]); for (int i = 0; i < length; i++) { printf("Score %d: %d\n", i + 1, scores[i]); } return 0;}


? Types of Arrays

1. One-Dimensional Array

c

char vowels[] = {'a', 'e', 'i', 'o', 'u'};

2. Multi-Dimensional Array (2D)

c

int matrix[2][3] = { {1, 2, 3}, {4, 5, 6}};

Access like: matrix[0][2] ? 3


?? Array Boundaries

C does not check array bounds! Be careful not to go out of range:

c

int arr[3] = {1, 2, 3};arr[5] = 10; // ? undefined behavior!


? Bonus: String as Char Array

c

char name[] = "Alice";printf("%s", name); // prints Alice

It's actually a character array: ['A', 'l', 'i', 'c', 'e', '\0']


Want help with:

  • 2D array operations?

  • Sorting arrays?

  • Passing arrays to functions?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql