Ict 1
Ict 1
To access array elements access strings, refer to its index number (Indexes are used to
access elements in an array). Array indexes start with 0; [0] is the first element, [1] String Functions
is the second element, etc.
int myNumbers[] = {25, 50, 75, 100}; There are multiple string functions that perform specific tasks. To use them, you
printf("%d", myNumbers[0]); must include <string.h> header file in your program.
The result should be 25, as it is the first element.
For example, to get the string length, you can use the strlen() function
To change the value of an element modify strings, refer to its index number:
// Add elements
myNumbers[0] = 25;
myNumbers[1] = 50;
myNumbers[2] = 75;
myNumbers[3] = 100;
Using this method can show the amount of array elements in advance, letting the To concatenate strings, you can use the strcat() function:
program set enough storage for said elements. The size of the array isn’t
changeable after creation.
To get the size of an array, you can use the sizeof operator:
The size differs depending on its data type, char is 1, int is 2 or 4, float is 4,
double is 8. So, if there are four array elements in an array, you multiply that by
the data type of the elements in the array (assuming there aren’t multiple data
types).
int myNumbers[] = {25, 50, 75, 100}; To compare strings, you can use the strcmp() function. It returns 0 if the two
int length = sizeof(myNumbers) strings are equal, otherwise, a value that isn’t 0:
/ sizeof(myNumbers[0]);
printf("%d", length);
The result should be 4, as there are four array elements in the given array.
Escape Characters