1. What is an array in C?
Answer:
Explanation:
In C, an array is a data structure that can store a fixed-size sequential collection of elements of the same type.
2. How is an array declared in C?
Answer:
Explanation:
An array is declared in C by specifying the data type of its elements, followed by the array name and its size in square brackets.
3. Which of the following array declarations is correct in C?
Answer:
Explanation:
All these declarations are correct ways to declare arrays in C.
4. How do you access the third element in an array named 'data' in C?
Answer:
Explanation:
Array indices in C start from 0, so the third element is accessed using data[2].
5. What is the default value of elements in an uninitialized array in C?
Answer:
Explanation:
Uninitialized array elements in C contain garbage values (i.e., whatever value is already at the memory location).
6. What is the size of an array 'arr' declared as int arr[10] in C?
Answer:
Explanation:
The size of the array depends on the size of an int on the system. Typically, if an int is 4 bytes, the array size would be 4 bytes * 10 = 40 bytes.
7. How can the number of elements in an array be determined in C?
Answer:
Explanation:
The number of elements in an array can be determined by dividing the total size of the array (obtained using sizeof) by the size of an element.
8. What is the output of the following C code?
int arr[] = {1, 2, 3, 4, 5};
printf("%d", arr[3]);
Answer:
Explanation:
Array indices start at 0, so arr[3] refers to the fourth element, which is 4.
9. Which of the following is a correct way to initialize an array in C?
Answer:
Explanation:
Both a) and c) are correct. In a), all elements are initialized to 0. In c), the array size is determined by the number of elements in the initializer.
10. Can the size of an array be changed at runtime in C?
Answer:
Explanation:
In C, the size of an array is fixed at compile-time and cannot be changed at runtime.
11. What is a multidimensional array in C?
Answer:
Explanation:
A multidimensional array in C is an array whose elements are themselves arrays.
12. How do you initialize a two-dimensional array in C?
Answer:
Explanation:
A two-dimensional array is initialized using nested initializer lists, each representing a row of the array.
13. What does array decay refer to in C?
Answer:
Explanation:
Array decay is the process where an array loses its type and size information and becomes a pointer to its first element.
14. What is the output of the following C code?
int arr[3] = {0};
printf("%d %d %d", arr[0], arr[1], arr[2]);
Answer:
Explanation:
The array is initialized with all elements set to 0, so the output will be 0 0 0.
15. Which of the following statements about arrays in C is correct?
Answer:
Explanation:
In C, the size of an array must be known at compile time and must be a constant expression.
16. What is a pointer to an array in C?
Answer:
Explanation:
A pointer to an array in C is a variable that stores the address of the first element of the array.
17. How do you pass an array to a function in C?
Answer:
Explanation:
In C, an array is passed to a function by passing the array name, which is a pointer to the first element of the array.
18. Can an array contain a pointer in C?
Answer:
Explanation:
An array in C can contain pointers as its elements.
19. What is the relationship between arrays and pointers in C?
Answer:
Explanation:
In C, arrays and pointers are closely related. An array name can be treated as a pointer to the first element of the array.
20. What is the output of the following C code?
int arr[] = {1, 2, 3};
printf("%d", *(arr + 1));
Answer:
Explanation:
The expression *(arr + 1) is equivalent to arr[1], which accesses the second element of the array, giving the output 2.
Comments
Post a Comment
Leave Comment