Important Introduction to Programming Short Questions
Chapter: 38
Question 1:
What is the sequence of destruction for static objects in a program?
Answer:
Static objects are destroyed in the reverse order of their creation, after the program execution completes.
Chapter: 38
Question 2:
How can static data members be accessed in a class?
Answer:
They should be accessed using the class name, e.g., ClassName::staticMember, rather than through instances of the class.
Chapter: 38
Question 3:
What does the static keyword mean in the context of a class?
Answer:
It indicates that the data member is shared among all instances of the class and exists independently of any objects of that class.
Chapter: 38
Question 4:
How do you keep track of the number of objects of a class using static data members?
Answer:
Use a static data member in the class to increment or decrement the count in the constructor and destructor, respectively.
Chapter: 39
Question 5:
What is a pointer in programming?
Answer:
A pointer is a special type of variable that holds the memory address of another variable rather than a value.
Chapter: 39
Question 6:
Can pointers in C++ be typed?
Answer:
Yes, pointers in C++ can be typed (e.g., pointers to integers, characters, floats) or be void pointers.
Chapter: 39
Question 7:
How do you get the address of a variable in C++?
Answer:
You use the & operator to obtain the address of a variable.
Chapter: 39
Question 8:
What is the difference between a pointer and a reference?
Answer:
A pointer can be null or uninitialized, while a reference must always refer to an object or variable.
Chapter: 39
Question 9:
What is call by value?
Answer:
Call by value creates a copy of the variable's value and passes it to the function, leaving the original value unchanged.
Chapter: 39
Question 10:
What is call by reference?
Answer:
Call by reference passes the address of a variable to the function, allowing the function to modify the original variable.