Lesson1 Flashcards
(92 cards)
What is an array in C?
A collection of similar type of data items stored at contiguous memory locations
How do you declare an array in C?
data_type array_name[array_size];
What is the syntax for initializing an array during declaration?
data_type array_name[size] = {value1, value2, …, valueN};
What is the starting index for arrays in C?
0
What function is used to find the length of a string in C?
strlen
What is the purpose of pointers in C?
To store the address of another variable
True or False: An array can only store primitive data types.
True
Fill in the blank: An array is the simplest _______ structure in C.
data
What is the syntax for accessing an element in an array?
array_name[index];
What are the two types of arrays mentioned?
- One-dimensional arrays
- Two-dimensional arrays
How do you initialize an array using index?
By assigning values to each index individually, e.g., Arr[0]=value;
What is a two-dimensional array?
An array of one-dimensional arrays, visualized as a table with rows and columns
What is the output of accessing arr[1][0] in a 2D array defined as int arr[2][3] = { {1, 4, 2}, {3, 6, 8} };?
3
What is the purpose of the ‘sizeof’ operator in the context of arrays?
To determine the size of the array in bytes
What does the term ‘self-referential structure’ refer to?
A structure that contains a pointer to its own type
True or False: You can use pointers to access elements of an array.
True
How do you read values into an array in C?
Using a loop and scanf to input each value
What is the output of the following code snippet? int marks[5] = {80, 60, 70, 85, 75}; printf(‘%d’, marks[2]);
70
How do you find the sum of elements in an array?
Using a loop to iterate through the array and accumulate the sum
What is the formula to calculate the average of an array?
average = sum / number_of_elements
What is the syntax for defining a structure in C?
struct structure_name { data_type member1; data_type member2; … };
What is an example of a basic string function in C?
- strcat
- strcpy
- strstr
Fill in the blank: A _______ can store multiple values in a single variable.
array
What does ‘union’ in C allow you to do?
Store different data types in the same memory location