Skip to main content

Important Introduction to Programming Short Questions

Chapter: 10
Question 1:
How does a compiler handle #define constants?
Answer: The compiler replaces the #define constants with their values during the pre-processing phase.
Chapter: 11
Question 2:
What is an array in C?
Answer: An array in C is a data structure that can hold multiple elements of the same data type in a contiguous block of memory.
Chapter: 11
Question 3:
How do you declare an array of 10 integers in C?
Answer: You declare an array of 10 integers in C using the syntax: int array_name[10];.
Chapter: 11
Question 4:
What is the starting index of an array in C?
Answer: The starting index of an array in C is 0.
Chapter: 11
Question 5:
How is the size of an array defined in C?
Answer: The size of an array in C is defined by the number inside the square brackets during declaration, e.g., int arr[10]; defines an array of size 10.
Chapter: 11
Question 6:
How do you access the third element in an array int arr[5]?
Answer: You access the third element in an array int arr[5] using arr[2].
Chapter: 11
Question 7:
What does int age[10] = {0}; do?
Answer: int age[10] = {0}; initializes all 10 elements of the age array to 0.
Chapter: 11
Question 8:
Why is it not recommended to use default initialization of arrays?
Answer: It’s not recommended to use default initialization because the compiler might assign garbage values to the array elements if not explicitly initialized.
Chapter: 11
Question 9:
How do you copy one array to another in C?
Answer: You can copy one array to another using a loop: for (i = 0; i < size; i++) { b[i] = a[i]; }.
Chapter: 11
Question 10:
What happens when you declare an array with int arr[] = {1, 2, 3};?
Answer: The compiler automatically determines the size of the array based on the number of elements in the initialization list, which in this case is 3.