C Arrays
Arrays in C are used to store multiple values of the same type in a single variable. They occupy contiguous memory locations.
C प्रोग्रामिंग में arrays का उपयोग एक ही प्रकार के कई मानों को एक ही variable में संग्रहित करने के लिए किया जाता है। ये लगातार memory locations में संग्रहीत होते हैं।
Accessing Array Elements
This program prints all elements of the array using a loop.
यह प्रोग्राम loop का उपयोग करके array के सभी elements को print करता है।
#include <stdio.h>
int main() {
int numbers[5] = {10, 20, 30, 40, 50};
for(int i = 0; i < 5; i++) {
printf("%d\n", numbers[i]);
}
return 0;
}
10
20
30
40
50
Sum of Array Elements
This program calculates and prints the sum of array elements.
यह प्रोग्राम array के सभी elements का sum निकालता है और print करता है।
#include <stdio.h>
int main() {
int arr[4] = {1, 2, 3, 4};
int sum = 0;
for(int i = 0; i < 4; i++) {
sum += arr[i];
}
printf("Sum = %d", sum);
return 0;
}
Sum = 10