Skip to main content

Important Introduction to Programming Short Questions

Chapter: 28
Question 1:
How do you access data members of a structure?
Answer: Data members of a structure are accessed using the dot operator (.), like objectName.dataMember.
Chapter: 28
Question 2:
How do you declare a pointer to a structure object?
Answer: A pointer to a structure object is declared as struct StructName *pointerName;.
Chapter: 28
Question 3:
What is the purpose of the malloc() function in C?
Answer: The malloc() function in C dynamically allocates memory during runtime and returns a void pointer to the allocated memory.
Chapter: 28
Question 4:
How do you allocate memory for an integer using malloc() in C?
Answer: You can allocate memory for an integer using malloc(sizeof(int)); in C.
Chapter: 28
Question 5:
What is a void pointer in C, and how is it used?
Answer: A void pointer in C is a pointer that can point to any data type. It needs to be cast to the appropriate type before use.
Chapter: 28
Question 6:
What is the difference between malloc() in C and new in C++?
Answer: malloc() in C requires specifying the number of bytes to allocate, and the memory is not initialized. In contrast, new in C++ allocates memory and returns a pointer of the required type, automatically initializing the object if a constructor is defined.
Chapter: 28
Question 7:
What is the operator used to deallocate memory in C++?
Answer: The delete operator is used to deallocate memory that was allocated using the new operator in C++.
Chapter: 28
Question 8:
How do you allocate an array of integers dynamically in C++?
Answer: You allocate an array of integers dynamically in C++ using the syntax int *iptr = new int[10];.
Chapter: 28
Question 9:
What happens if the memory requested by new cannot be allocated in C++?
Answer: If new cannot allocate the requested memory, it returns 0 (null pointer).
Chapter: 28
Question 10:
How does the delete operator work in C++?
Answer: The delete operator deallocates the memory that was allocated by new, returning it to the free store.