Skip to main content

Important Introduction to Programming Short Questions

Chapter: 12
Question 1:
How can you display a string stored in a character array?
Answer: You can display the string using cout << name; or by iterating through the array with a loop and displaying each character until the null character is encountered.
Chapter: 12
Question 2:
Why is it important to check for the null character when displaying a string using a loop?
Answer: Checking for the null character prevents the display of garbage values that may be present in the array beyond the end of the string.
Chapter: 12
Question 3:
How can you compare two character arrays for equality?
Answer: You can compare two character arrays by checking each corresponding character in a loop. If all characters match, the arrays are equal; otherwise, they are not.
Chapter: 12
Question 4:
What is the importance of the not-equal operator in comparing arrays?
Answer: The not-equal (!=) operator allows early termination of the comparison if a mismatch is found, saving unnecessary comparisons.
Chapter: 12
Question 5:
How does C handle case sensitivity in string comparison?
Answer: C is case-sensitive, meaning characters like 'A' and 'a' are considered different, so "AZMAT" is not equal to "azmat".
Chapter: 12
Question 6:
How does the swapping technique work in array sorting?
Answer: In swapping, two array elements are exchanged by using a temporary variable to hold one value while the other is assigned, ensuring neither is lost.
Chapter: 12
Question 7:
What is the difference between linear search and binary search?
Answer: Linear search compares each element sequentially, while binary search divides the array and eliminates half each time based on whether the target is greater or lesser than the middle element.
Chapter: 12
Question 8:
Why is binary search more efficient than linear search?
Answer: Binary search reduces the search space by half in each iteration, making it significantly faster than linear search, especially for large arrays.
Chapter: 12
Question 9:
What is the default calling mechanism for functions in C when passing arrays?
Answer: The default mechanism is 'call by reference,' meaning the original array is passed to the function, allowing direct modification of the array's elements.
Chapter: 12
Question 10:
How do you pass a character array to a function in C?
Answer: You pass a character array by its name and the size of the array. The array name represents the address of the first element, and the size informs the function of the array's length.