OOP Flashcards

1
Q

What are function prototypes used for?

A

They are used to tell the compiler how the function was defined without having to write the function before the calling function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

By default when passing a value to a function in C++ is the passed argument a reference type or not?

A

By default the passed argument is a copy and not a reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can you set default arguments in functions?

A

yes just like in most other languages

calc_cost(double base_cost = 0.0.6)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can I just pass an array to a function?

A

Arrays are pointing to its address in memory so a function has no access to the array size. The size needs to be passed to the function as well.

Also since the array is pointing to the original address the array is passed as a reference type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can I use pass by reference in C++

A

by using the ampersand we can pass by reference an argument to a function.

void swap(int &a, int &b);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly