Skip to main content

Important Introduction to Programming Short Questions

Chapter: 14
Question 1:
What is the syntax for declaring a pointer?
Answer: The syntax for declaring a pointer is: data_type *pointer_name; where data_type is the type of data the pointer will reference.
Chapter: 14
Question 2:
How do you assign the address of a variable to a pointer?
Answer: You use the address operator & to assign the address of a variable to a pointer, like this: ptr = &x; where ptr is a pointer and x is a variable.
Chapter: 14
Question 3:
What does the dereferencing operator (*) do in C?
Answer: The dereferencing operator * is used to access the value stored at the memory address held by a pointer. For example, *ptr retrieves the value pointed to by ptr.
Chapter: 14
Question 4:
How do you initialize a pointer to NULL?
Answer: A pointer can be initialized to NULL using ptr = NULL;, indicating that the pointer currently points to no valid memory address.
Chapter: 14
Question 5:
What is a call by reference in C?
Answer: Call by reference is when a function is passed the address of a variable, allowing the function to modify the actual value stored at that memory address.
Chapter: 14
Question 6:
How does bubble sort utilize pointers for swapping values?
Answer: In bubble sort, pointers can be used to swap values in an array by passing the addresses of the elements to a swap function, which then interchanges the values directly at those addresses.
Chapter: 14
Question 7:
What does the keyword const do when used with pointers?
Answer: When const is used with a pointer, it can either make the pointer itself constant or the value it points to constant, depending on the placement of const.
Chapter: 14
Question 8:
What is a NULL pointer?
Answer: A NULL pointer is a pointer that is assigned the value NULL, indicating that it does not currently point to any valid memory location.
Chapter: 14
Question 9:
How do you convert a string to uppercase using pointers?
Answer: You can convert a string to uppercase by iterating through the string with a pointer, checking each character with islower, and converting it using toupper.
Chapter: 14
Question 10:
What is the role of the & operator in function calls?
Answer: The & operator is used in function calls to pass the address of a variable, enabling the function to directly modify the variable's value in memory.