C++ LinkedIn Skill Assessments Quizzes with Answers 2022

chase2learn.com
3 min readOct 19, 2022

Linkedin C++ Assessment Answers

Q1. What is printed from this code?

C++

vector<int> v(22);bool b = (v[6]);printf("%d", !b);
  • [ ] False
  • [ ] 0
  • [x] 1
  • [ ] This code has an error.

Q2. Which of the following is a reason why using this line is considered a bad practice? (Alternative: Why is using this line considered a bad practice?)

C++

Using namespace std;
  • [ ] The compiled code is always bigger because of all of the imported symbols.
  • [x] If the code uses a function defined in two different libraries with the same prototype but possibly with different implementations, there will be a compilation error due to ambiguity.
  • [ ] It automatically includes all header files in the standard library (cstdint, cstdlib, cstdio, iostream, etc).
  • [ ] It causes the compiler to enforce the exclusive inclusion of header files belonging to the standard library, generating compilation error when a different header file is included.

Reference

Q3. What is the smallest size a variable of the type child_t may occupy in memory?

C++

typedef struct{unsigned int  age    : 4;unsigned char gender : 1;unsigned int  size   : 2;}child_t;
  • [x] 7 bits.
  • [ ] 25 bytes.
  • [ ] 1 bit.
  • [ ] 1 byte.

Reference

Q4. Which of the following shows the contents of vector v1 and v2 after running this code?

C++

std::vector<int> v1{1,2,3},v2;v2=v1;v1.push_back(4);v2.push_back(5);
  • [ ] Error
  • [ ] v1:{1,2,3,4}; v2:{5};
  • [ ] v1:{1,2,3,4,5}; v2:{1,2,3,4,5};
  • [x] v1:{1,2,3,4}; v2:{1,2,3,5};

Q5. Which of the following is a true statement about the difference between pointers and iterators?

  • [ ] While pointers are variable that hold memory address, iterators are generic functions used to traverse containers. These function allows the programmer to implement read and write code as the container is traversed.
  • [x] Incrementing an iterator always means access the next element in the container(if any), no matter the container. Incrementing the pointer means pointing to the next element in memory, not always the next element.
  • [ ] Pointers are variables that hold memory address where as iterator are unsigned integers that refers to offsets in arrays.
  • [ ] All iterator are implemented with pointers so all iterators are pointers but not all pointers are iterators.

Reference

Q6. What’s a benefit of declaring the parameter as a const reference instead of declaring it as a regular object?

C++

int median(const my_array& a);
  • [ ] The argument is passed as a reference, so the function receives a copy that can be modified without affecting the original value.
  • [x] The argument is passed as a reference, so if the passed my_array object is large, the program will require less time and memory.
  • [ ] Actually objects can’t be passed as regular variables because they require a constructor call. Therefore a const reference is the only way to pass class instances to functions.
  • [ ] There are no benefits because a reference and an object are treated as the same thing.

Reference

Q7. What’s the storage occupied by u1?

C++

union {unit16_t a;unit32_t b;int8_t c;} u1;
  • [x] 4 bytes
  • [ ] 7 bytes
  • [ ] 8 bytes
  • [ ] 2 bytes

Reference

Q8. Which of the following operators is overloadable?

  • [ ] ?:
  • [x] new
  • [ ] ::
  • [ ] .

Reference

Q9. Which of the following shows the contents of vector pointed by v1 and v2 after running this code?

C++

std:: vector<int> *v1 = new std::vector<int>({1,2,3});std:: vector<int> *v2;v2=v1;v1->push_back(4);v2->push_back(5);
  • [ ] *v1:{1,2,3,4}; *v2:{5};
  • [x] *v1:{1,2,3,4,5}; *v2:{1,2,3,4,5};
  • [ ] Error
  • [ ] *v1:{1,2,3,4}; *v2:{1,2,3,5};

v1 and v2 point to the same vector.

Q10. Which of the following is not a difference between a class and a struct?

  • [ ] Because structs are part of the C programming language, there are some complexity between C and C++ structs. This is not the case with classes.
  • [x] Classes may have member functions; structs are private.
  • [ ] The default access specifier for members of struct is public, whereas for member of class, it is private.
  • [ ] Template type parameters can be declared with classes, but not with the struct keyword.

Reference

fore more questions and answers please visit

--

--

chase2learn.com

one place| Learn Gain Continue the Chase! Corner for CS, Software engineering, ML, AI, Software Developers, Programmers, CareerPath, Interviews questions.