• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 83 pages
Exam (elaborations)

UCT CSC3022 C++ Section correctly answered to pass

Document preview thumbnail
Preview 4 out of 83 pages

UCT CSC3022 C++ Section correctly answered to pass

Content preview

UCT CSC3022 C++ Section correctly
answered to pass

What are the big 6? - correct answer ✔✔copy constructor, move constructor, copy
assignment, move assignment, destructor, constructor


how do you denote a generic pointer? - correct answer ✔✔void * ptr ; this has no
specific type so BEFORE it can be used it MUST be cast to the appropriate type


what is the relationship between arrays and pointers in C++? - correct answer
✔✔C++ considers the array variable name to be a POINTER to the first element of
the array


How do you avoid multiple file inclusions and what do they cause if not handled? -
correct answer ✔✔include gaurds prevent compiliation errors
use preprocessor directives as follows
#ifndef _SOMENAME
#define _SOMENAME
#include <filename>
void do_stuff();
#endif


given the macro definition
#define EXPR(y) y/3

,what will std::cout << EXPR(3); expand to? - correct answer ✔✔because macros
are simple in text substitutions the macro will expand simply to produce:
3/3


how does a copy constructor differ from a move constructor? - correct answer
✔✔- a copy constructor builds a new instance of the type by creating NEW copies
of ALL its data
- a move constructor creates an EMPTY object annd then transfers ALL the data
from the source object into the new object essentially deleting the previous
object.


given the operator overload function
Object Object::operator-(const Object & obj);
Can we return the obj by reference? - correct answer ✔✔this is a unary minus it
needs to modify the value passed in by the argument and pass back a modified
version. However the object passed in is const and so it cannot simply just modify
obj and pass that back. We must create a copy internally and pass back the copy
by VALUE.


what is the difference between pass by value and pass by reference in C++? -
correct answer ✔✔given: int x = 10; int y = 2;


pass by value
someFunction(x,y);


pass by reference
someOtherFunction(int *ptx,

,explain the variable actions in each of the following statements: - correct answer
✔✔int a = 5; // declare an integer simply
int * ptr = nullptr; // declare and int ptr and init to nullptr
ptr = &a; //set ptr to point to a by using the address operator to get the address of
a
int b = *ptr; // use the dereference operator * to set b to a
*ptr = 6; // use the dereference operator to set the variable ptr points to (a) to
have a value of 6


when do you not need any code in the destructor for a class? - correct answer
✔✔if the only variables are automatic variables (ints, strings) then you do not
need code in the destructors because when these variables go out of scope their
destructors will be called automatically


what is the difference between the following include statements?
#include <filename>
#include "filename" - correct answer ✔✔the carrots search default dirs (used for
built in files). the quotes searches explicit include dirs (used for header files
written by the user)


are lambdas and functors equivalent in application? if not, describe where and
how the different in use. if so, describe the most common use for them and what
makes them interchangeable. - correct answer ✔✔functors and lambdas are
equivalent in application. lambdas are a lightweight "syntactic sugar" alternative
to functors. they have the advantage over functors that one does not need to
define and instantiate a class. But they are INTERCHANGABLE as they are both
locally scoped "ad-hoc" (as needed/situation specific)

, what is the syntax for a tenary operator? - correct answer ✔✔condition ?
expression1 : expression 2
examples:
marks = 10
string result = (marks > 20) ? "passed" : "failed";


number = -1
bool eval = (number > 0) ? true: false;


what is the value of c++ templates? - correct answer ✔✔


what does the #include directive accomplish in a c++ source file? - correct answer
✔✔the #include directive in a c++ source file inserts the header file TEXT into the
current source file


Define a pre-processor macro, PRN(x) that writes the value x to std::cout? -
correct answer ✔✔#define PRN(x) std::cout << (x) << std::endl;
note: HAVE TO include the parenthesis around the x because macros do text
substitution and if you don't put the parenthesis for this case than an input like
PRN(x+y) is gonna cause a compilation error


what is the difference between a pointer and a reference in c++? - correct answer
✔✔references refer to an existing variable with another name whereas pointers
store the ADDRESS of a variable


int x = 3;
int & xr = x; // this is a reference

Document information

Uploaded on
January 26, 2025
Number of pages
83
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$28.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
BravelRadon
3.5
(164)
Sold
963
Followers
541
Items
53650
Last sold
1 day ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions