Lesson1 Flashcards
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
What is the maximum number of dimensions an array can have in C?
Theoretically, it can be up to 255 dimensions
What does the term ‘enumeration data type’ refer to?
A user-defined type consisting of a set of named integer constants
How is memory allocated for an array in C?
The compiler allocates a block of memory based on the array’s size upon declaration
True or False: Arrays in C can only hold integers.
False
What is the output of the following code snippet? printf(‘%d’, marks[5]); where marks is defined as int marks[5];
Undefined behavior (out of bounds access)
How do you sort an array in C?
Using a sorting algorithm like bubble sort, quicksort, etc.
What are the two main operations performed on arrays?
- Accessing elements
- Modifying elements
What is the significance of the index in an array?
It determines the position of an element within the array
What is the syntax to declare a two-dimensional array?
data_type array_name[rows][columns];
What is a string in C?
A one-dimensional array of characters terminated by a null character (‘\0’)
The null character is crucial for identifying the end of the string.
What differentiates a character array from a C string?
A C string is terminated with a unique character ‘\0’
This termination character allows the program to determine where the string ends.
What is the syntax for declaring a C string?
char string_name[size];