Topics for C++ exam need explanations and examples of these. Understand the diff
ID: 3573826 • Letter: T
Question
Topics for C++ exam need explanations and examples of these.
Understand the difference between recursion and iteration. When should we use loops? Recursion?
Be able to create arrays and vectors.
Be able to initialize arrays.
Be able to create, access, and modify multi-dimensional arrays.
Be able to access arrays using pointer notation.
Understand the concept of pointers. How to declare them.
Understand the use of the dereference operator (*) in pointers.
Explain the difference of non-constant pointer to non-constant data, constant pointer to non-constant data, non-constant pointer to constant data, and constant pointer to constant data.
Understand the relationship between arrays and pointers.
Be able to pass function pointers as parameters.
Be able to declare and implement friend functions.
Be able to overload operators in a class both as global and member functions.
Be able to create a class, separating the interface (header file) from the implementation (source file).
Know how to access members of an object through an object reference. i.e. a pointer.
Describe the purpose of new, new[], delete, and delete[].
Be able to use a class hierarchy applying polymorphism.
Explanation / Answer
1)
Recursion: is basically calling the same function again and changing the values to its arguments depending on our requirement like if we want to calculate factorial of number the pattern is 5*4*3*2*1, so it's just multiplying numbers with one less value every time so we will call the same function with passing (n-1) value.
Whereas
Iteration: is looping over same instruction for a specific time (same instruction needs to be executed n times) and it will be done using loops for e.g. factorial can be calculated using loop 5*4*3*2*1 (iterate multiplication instruction 5 times)
int fac= 1;
for(i=1;i<=5;i++
{fac = fac*i;
}
Here we are same instruction fac = fac*i 5 times