Arrays and Strings Flashcards

(8 cards)

1
Q

What is the syntax to declare a one-dimensional integer array named data that can hold 10 elements?

A

int data[10];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you initialize a one-dimensional array numbers with the values 1, 2, 3, 4, 5 during declaration?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you read 5 integer elements into an array M using a for loop and scanf()?

A

int M[5], i;
for (i = 0; i < 5; i++) {
printf(“Enter element %d: “, i + 1);
scanf(“%d”, &M[i]);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the syntax for passing an entire one-dimensional array named myArray and its size to a function named processArray?

A

Function Prototype: void processArray(int arr[] or int* arr, int size);

Function Call: processArray(myArray, arraySize);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you declare and initialize a 2D integer array (matrix) with 2 rows and 3 columns?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a C string? How is it terminated?

A

A sequence of characters stored in a one-dimensional character array, terminated by a null character (\0).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Name two string manipulation functions from <string.h> and their purpose.</string.h>

A

strlen(string): Returns the length of the string (excluding \0).

strcpy(destination, source): Copies the source string to destination.

strcat(destination, source): Concatenates source to the end of destination.

strcmp(string1, string2): Compares two strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you declare a string variable myString that can hold up to 20 characters (including the null terminator)?

A

char myString[20];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly