An array is a collection of variables of the same type that are stored in contiguous memory locations. Think of it as a row of boxes, each box holding one value, and all boxes being of the same kind (type).
Arrays help you store and manage multiple values using a single variable name with an index to access each value.
0.int numbers[5] = {10, 20, 30, 40, 50};
printf("%d\n", numbers[2]); // Outputs 30
Here, numbers is an array of 5 integers. We access the 3rd element using numbers[2] because indexes start at 0.
A string is a sequence of characters stored as an array of char elements in C.
It is terminated with a special character called the null character represented as '\0'.
This null character marks the end of the string so functions know where the string stops.
char variable.'\0'): A special character indicating the end of a string.char name[] = "Rahul";
printf("%s\n", name); // Outputs Rahul
Here, name is a character array holding the characters 'K', 'a', 'p', 'i', 'l', and '\0' (end marker).
array[0] for the first element.numbers[1] = 25;for or while to process elements.strlen(), strcpy(), strcmp() from string.h to work with strings.int i;
int numbers[5] = {10, 20, 30, 40, 50};
for (i = 0; i < 5; i++) {
printf("Element %d: %d\n", i, numbers[i]);
}
strlen(str) – Returns the length of the string (excluding '\0').strcpy(dest, src) – Copies the source string into the destination.strcmp(str1, str2) – Compares two strings and returns 0 if they are equal.strcat(dest, src) – Concatenates (appends) the source string to the destination string.strlen().strcat().