Hello, recently I was presented with this test that covers very various details of C++. I found myself not knowing most of the answers, but I did fair well, considering I've only known C++ for a few months. I would like to improve myself, and try to learn about potential pitfalls, optimization, and other fine details of C++. The test is as following, to provide what some information of what i cam talking about. Please keep in mind, I'm not talking about these question in specific, just anything similar to these.
Please don't post this any where else, I would like to keep it contained
Thanks
So, any sites, or resources that has good information would be highly appreciated!
Thanks,
Jedd
I think this was my c++ final in college.
* What is the difference between between a const global variable and a #define? Where would you use one over the other?
const is a c++ construct that makes a variable constant and unable to change. The difference is it provides strong compile time checking.
* Difference between:
const int * const foo->const pointer integer
const int * foo->pointer integer
int * const foo->const integer pointer
* What is the difference between a recursive function and loops? Give an example of each.
recursive is a function that call itself. There is some math definition, but hell if i remember it.
* Write a bubble sort function
void BubbleSort (int * IntArray, const unsigned int ArraySize)
{
google bubble
}
* What errors would occur in the following code and why?
class Blah
{
private:
int Foo;
public:
Blah() { Foo = 10; }
~Blah() {}
MyFunction ( int &Mobor)
{
Mobor += 10;
}
};
int main( int argc, char **argv)
{
Blah * ptr = 0;
ptr->MyFunction(10);
return 0;
}
calling a method in class that hasn't been instantiated and is isn't a native c++ type. You probably need void in front of my function.
* What does a static variable do in a function?
variables get set and compile time. so when you run your software the static variables are already in memory.
* What is a ring buffer and how does a it differ from a standard queue?
i think a ring buffer is a circular queue which means there is pointer at the points back to the other end.
* What does "in place" mean (regarding algorithms)? Give an example.
no idea
* What are the differences between an Octree, Quadtree and a BSP? What can they be used for?
bsp stores branches of a polygon i believe. I don't what the others do
* Optimise this function:
const int Sum (const int * LotsOfNumbers, const unsigned int Size )
{
int Sum = 0;
for(int i = 0; i < Size; ++i)
{
Sum += LotsOfNumbers[ i ];
}
return Sum;
}
optimize in terms of what?
* The difference between ++i and i++;
++i is run before the line is executed.
i++ is run after.
* Describe a use of a function pointer and suggest other methods to produce the same effect.
pointer is a memory address. it sort of a stupid question.
* What is a template class? What an example that stores an object with a function that squares itself returning the object as a const. Give an example why this would not work with all objects.
i don't the definition.
* What is the difference between an Interface class and an Abstract class?
good question
* What is wrong with the following piece of code and how would you fix it? What would be the result of the error and
why?
class A
{
private:
int *AInt;
public:
A() { AInt = new int(0); } //int nTemp = 0; AInt = &nTemp;
~A() { delete AInt; } // {}
};
class B : public A //class B
{
private:
int *BInt;
public:
B() { BInt = new int(0); }//int nTemp = 0; AInt = &nTemp;
~B() { delete BInt; } //{}
};