أخر الاخبار

إجابة تقييم المهارات لـ ++C على LinkedIn

 تقييم المهارات لـ ++C على LinkedIn

إجابة تقييم المهارات لـ ++C على LinkedIn






امتحان مهارات اللينكدان في ++C :






تعتبر لغة البرمجة ++ واحدة من أكثر اللغات شهرة واستخدامًا في عالم التكنولوجيا، وقد أصبحت مهارة البرمجة بهذه اللغة من المهارات المطلوبة في العديد من الوظائف التقنية. تقوم منصة اللينكدان بتقديم امتحان لقياس مهارات الأشخاص في هذه اللغة، وذلك بهدف مساعدة أصحاب العمل على تحديد الأشخاص الأكثر كفاءة في هذا المجال.


في هذا المقال ، ستجد مجموعة من الأسئلة والأجوبة التي ستظهر في امتحان اللينكدان لمهارات ++C . يمكن الاعتماد على هذه الأسئلة كمرجع للتحضير للامتحان، ولكن يجب العلم أن النجاح في الامتحان يتطلب فهمًا عميقًا للغة وليس فقط حفظ الأسئلة والأجوبة.





Q1. What is printed from this code?
vector<int> v(22);
bool b = (v[6]);
printf("%d", !b);

  1. False
  2. 0
  3. 1✔️
  4. 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?)
Using namespace std;

  1. The compiled code is always bigger because of all of the imported symbols.
  2. 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.✔️
  3. It automatically includes all header files in the standard library (cstdint, cstdlib, cstdio, iostream, etc).
  4. 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.

Q3. What is the smallest size a variable of the type child_t may occupy in memory?
typedef struct{
unsigned int age : 4;
unsigned char gender : 1;
unsigned int size : 2;
}child_t;

  1. 7 bits.✔️
  2. 25 bytes.
  3. 1 bit.
  4. 1 byte.




Q4. Which of the following shows the contents of vector v1 and v2 after running this code?
std::vector<int> v1{1,2,3},v2;
v2=v1;
v1.push_back(4);
v2.push_back(5);

  1. Error
  2. v1:{1,2,3,4}; v2:{5};
  3. v1:{1,2,3,4,5}; v2:{1,2,3,4,5};
  4. 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?

  1. 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.
  2. 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.✔️
  3. Pointers are variables that hold memory address where as iterator are unsigned integers that refers to offsets in arrays.
  4. All iterator are implemented with pointers so all iterators are pointers but not all pointers are iterators.



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

int median(const my_array& a);
  1. The argument is passed as a reference, so the function receives a copy that can be modified without affecting the original value.
  2. The argument is passed as a reference, so if the passed my_array object is large, the program will require less time and memory.✔️
  3. 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.
  4. There are no benefits because a reference and an object are treated as the same thing.


Q7. What’s the storage occupied by u1?
union {
unit16_t a;
unit32_t b;
int8_t c;
} u1;

  1. 4 bytes✔️
  2. 7 bytes
  3. 8 bytes
  4. 2 bytes


Q8. Which of the following operators is overloadable?

  1. ?:
  2. new✔️
  3. ::
  4. .
Q9. Which of the following shows the contents of vector pointed by v1 and v2 after running this code?

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);

  1. *v1:{1,2,3,4}; *v2:{5};
  2. **v1:{1,2,3,4,5}; v2:{1,2,3,4,5};✔️
  3. Error
  4. *v1:{1,2,3,4}; *v2:{1,2,3,5};

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

  1. 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.
  2. Classes may have member functions; structs are private.
  3. The default access specifier for members of struct is public, whereas for member of class, it is private.
  4. Template type parameters can be declared with classes, but not with the struct keyword.✔️




Q11. Suppose you need to keep a data struct with permission to access some resource based on the days of the week, but you can’t use a bool variable for each day. You need to use one bit per day of the week. Which of the following is a correct implementation of a structure with bit fields for this application?

           A✔️

typedef struct {
int sunday:1;
int monday:1;
// more days
int friday:1;
int saturday:1;
} weekdays;


         B

typedef char[7]: weekdays;



         C

typedef struct {
bit sunday:1;
bit monday:1;
// more days
bit friday:1;
bit saturday:1;
} weekdays;


         D

typedef struct {
bit sunday;
bit monday;
// more days
bit friday;
bit saturday;
} weekdays;
Reference


Q12. What is an lvalue?

  1. It’s a constant expression, meaning an expression composed of constants and operations.
  2. It’s an expression that represents an object with an address.✔️
  3. It’s an expression suitable for the left-hand side operand in a binary operation.
  4. It’s a location value, meaning a memory address suitable for assigning to a pointer or reference.
Q13. What does auto type specifier do in this line of code (since C++11)?
auto x = 4000.22;

  1. It specifies that the type of x will be deduced from the initializer – in this case, double.✔️
  2. It specifies that the type of x is automatic meaning that if can be assigned different types of data throughout the program.
  3. It specifies that x is a variable with automatic storage duration.
  4. It specifies that more memory will be allocated for x in case it needs more space, avoiding loss of data due to overflow.
Q14. What is a class template?

  1. It’s a class written with the generic programming, specifying behavior in terms of type parameter rather than specific type.✔️
  2. It’s a blank superclass intended for inheritance and polymorphism.
  3. It’s class that only consists of member variable, with no constructor, destructor nor member functions.
  4. It’s skelton source code for a class where the programmer has to fill in specific parts to define the data types and algorithms used.
Q15. What is the ternary operator equivalent to this code snippet?

if(x)
y=a;
else
y=b;

  1. y=a?b:x;
  2. y=if(x?a:b);
  3. y=(x&a)?a:(x&b)?b:0;
  4. y=x?a:b;✔️
Q16. What is the output of this code?

#include <iostream>
int main(){
int x=10, y=20;
std::cout << "x = " << x++ << " and y = " << --y << std::endl;
std::cout << "x = " << x-- << " and y = " << ++y << std::endl;
return(0);
}

1. x = 10 and y = 20
x = 11 and y = 19

2. x = 11 and y = 19
x = 10 and y = 20

3. x = 10 and y = 19
x = 11 and y = 20✔️

4. x = 11 and y = 20
x = 10 and y = 19

Q17. What is the meaning of the two parts specified between parentheses in a range-based for loop, separated by a colon?

  1. The first is a variable declaration that will hold an element in a sequence. The second is the sequence to traverse.✔️
  2. The first is an iterator, and the second is the increment value to be added to the iterator.
  3. The first is the iterating variable. The second is an std::pair that specifies the range (start and end) in which the variable will iterate.
  4. The first is a container object. The second is an std::pair that specifies the range (start and end) in which the elements will be accessed within the loop.

Q18. What is the output of this piece of code?
int8_t a=200;
uint8_t b=100;
if(a>b)
std::cout<<"greater";
else
std::cout<<"less";

  1. There is no output because there is an exception when comparing an int8_t with a uint8_t.
  2. greater
  3. less✔️
  4. There is no output because there is a compiler error.
Q19. What results from executing this code snippet?
int x=5, y=2;
if(x & y) {
/*_part A_*/
}
else {
/*_part B_*/
}

  1. Part A executes because x==5 (true) and y==2 (true), thus the AND operation evaluates as true.
  2. Part B executes because (x & y) results in 0, or false.✔️
  3. Part A executes because (x & y) results in a nonzero value, or true.
  4. Part B executes because the statement (x & y) is invalid, thus false.
Q20. What is a valid definition for the get_length function, which returns the length of a null-terminated string?



A✔️
int get_length(char *str) {
int count=0;
while(str[count++]);
return count-1;
}

B
int get_length(char *str) {
int count=0;
while(str!=NULL){
count++;
str++;
}
return count;
}


C
int get_length(char *str) {
int count=0;
while((*str)++)
count++;
return count;
}


D
int get_length(char *str) {
int count=0;
while(str++)
count++;
return count;
}


Q21. Which STL class is the best fit for implementing a collection of data that is always ordered so that the pop operation always gets the greatest of the elements? Suppose you are interested only in push and pop operations.

  1. std::list
  2. std::vector
  3. std::priority_queue✔️
  4. std::map



Q22. What is the meaning of the three sections specified between parentheses in a for loop separated by semicolons?

  1. The first is the iterating variable name, the second is the number of times to iterate, and the third is the desired increment or decrement (specified with a signed integer).
  2. The first is the initialization block, the second is the condition to iterate, and the third is the increment block.✔️
  3. The first is the iterating variable, the second is the container in which it should operate, and the third is an exit condition to abort at any time.
  4. The first is the iterating variable name, the second is the starting value for the iterating variable, and the third is the stop value (the last value plus one).
Q23. What is printed from this code?
int i = 0;
printf("%d", i++);
printf("%d", i--);
printf("%d", ++i);
printf("%d", --i);
  1. 0,1,1,0✔️
  2. 0,1,0,1
  3. 0,0,1,0
  4. 1,0,1,0

Q24. What is true about the variable named ptr?
void *ptr;
  1. It is a pointer initialized at NULL.
  2. It is a pointer to a void function.
  3. That declaration causes a compiler error, as pointers must specify a type.
  4. It is a pointer to a value with no specific type, so it may be cast to point to any type.✔️


Q25. What is the output of this code?
int c=3; char d='A';
std::printf("c is %d and d is %c",c,d);

  1. c is d and d is c
  2. c is A and d is 3
  3. c is 3 and d is A✔️
  4. c is c and d is d

Q26. What is the output of this code?
printf("1/2 = %f",(float)(1/2));

  1. 1/2 = 0.499999
  2. 1/2 = 0
  3. 1/2 = 0.000000✔️
  4. 1/2 = 0.5
Q27. What is the difference between a public and a private class member?

  1. Public members are the same as global variables, so every part of the code has access to them. Private members are the same as automatic variables, so only their class has access to them.
  2. Public members are made accessible to any running application. Private members are made accessible only to the application where the object is instantiated.
  3. Public members will be compiled as shared variables in a multithreaded environment. Private members will be compiled as Thread-local variables.
  4. Public members can be accessed by any function. Private members can be accessed only by the same class’s member functions and the friends of the class.✔️
Q28. What is the value of x after running this code?
int x=10, a=-3;
x=+a;
  1. 3
  2. 7
  3. -3✔️
  4. 13
Q29. Which statement is true?

  1. Only classes can have member variables and methods.
  2. C++ supports multiple inheritance.✔️
  3. C++ supports only single inheritance.
  4. Only structs can inherit.
Q30. Consider a pointer to void, named ptr, which has been set to point to a floating point variable g. Which choice is a valid way to dereference ptr to assign its pointed value to a float variable f later in the program?
float g;
void *ptr=&g;
  1. float f=*(float)ptr;
  2. float f=(float *)ptr;
  3. float f=(float)*ptr;
  4. float f=*(float *)ptr;✔️


Q31. What is the .* operator and what does it do?

  1. It is the same as the class member access operator, or arrow operator (->), which allows you to access a member of an object through a pointer to the object.
  2. It is the pointer to member operator, and it allows you to access a member of an object through a pointer to that specific class member.✔️
  3. It is the member access with address of operator, which returns the address of a class or struct member.
  4. It is a combination of the member access operator (.) and the dereference operator (*), so it allows you to access the object that a member pointer points to.


Q32. For these declarations, which choice shows four equivalent ways to assign the character "y" in the string to a char variable c?
char buff[50] = "strings as arrays of characters are fun!"
char *str = buff+11;
char c;


A


c = buff[16];
c = str[5];
c = *(buff+16);
c = *(str+5);

B

c = *(buff[15]);
c = *(str[4]);
c = buff+15;
c = str+4;


C✔️

c = buff[15];
c = str[4];
c = *(buff+15);
c = *(str+4);

D

c = *(buff[16]);
c = *(str[5]);
c = buff+16;
c = str+5;


Q33. Which choice is the correct declaration for the class named Dog, derived from the Animal class?
class Animal{
//....
}

A

class Dog :: public Animal {
//....
};



B✔️

class Dog : public Animal {
//....
};



C

public class Animal :: Dog {
//....
};



D

public class Dog extends Animal {
//....
};



Q34. What is the output of this code?
#include <cstdio>
using namespace std;
int main(){
char c = 255;
if(c>10)
printf("c = %i, which is greater than 10", c);
else
printf("c = %i, which is less than 10", c);
return 0;
}
  1. c = -1, which is less than 10✔️
  2. c = 255, which is greater than 10
  3. c = -1, which is greater than 10
  4. c = 255, which is less than 10


Q35. How can C++ code call a C function?
  1. by simply calling the C code
  2. there is no way for C++ to call a C function
  3. by using extern "C"✔️
  4. by importing the source C code


Q36. Which choice is not a valid type definition of a structure that contains x and y coordinates as integers, and that can be used exactly as shown for the variable named center?
coord center;
center.x = 5;
center.y = 3;


A✔️

typedef struct coord {
int x;
int y;
};



B
typedef struct coord {
int x;
int y;
} coord;


C


typedef struct {
int x;
int y;
} coord;


D


struct coord {
int x;
int y;
};
typedef struct coord coord;



Q37. Which choice does not produce the same output as this code snippet? Assume the variable i will not be used anywhere else in the code.
for (i=1;i<10;i++){
cout<<i<<endl;
}



A✔️
i=1;
while(i<10){
cout<<++i<<endl;
}



B
for (int i:{1,2,3,4,5,6,7,8,9}) {
cout<<i<<endl;
}


C
i = 1;
do {
cout<<i++<<endl;
} while(i<10);



D
i = 1;
loop:
cout<<i++<<endl;
if(i<10) goto loop;



Q38. What does this part of a main.cpp file do?
#include "library.h"
  1. It causes the toolchain to compile all the contents of library.h so that its executable code is available when needed by the final application.
  2. It cherry picks library.h for the declarations and definitions of all data and functions used in the remainder of the source file main.cpp, finally replacing the #include directive by those declarations and definitions.
  3. It informs the linker that some functions or data used in the source file main.cpp are contained in library.h, so that they can be called in run time. This is also known as dynamic linking.
  4. It causes the replacement of the #include directive by the entire contents of the source file library.h. This is similar to a Copy-Paste operation of library.h into main.cpp.✔️


Q39. Consider this function declaration of is_even, which takes in an integer and returns true if the argument is an even number and false otherwise. Which declarations are correct for overloaded versions of that function to support floating point numbers and string representations of numbers?
bool is_even(int);




A✔️

bool is_even(float f);
bool is_even(char *str);


B

bool is_even(float f);
bool is_even(char str);


C

bool is_even_float(float f);
bool is_even_str(char *str);



D

float is_even(float f);
char *is_even(char *str);



Q40. Which choice is an include guard for the header file my_library.h?

A

#ifdef MY_LIBRARY_H
#define MY_LIBRARY_H
// my_library.h content
#endif /* MY_LIBRARY_H */

B✔️

#ifndef MY_LIBRARY_H
#define MY_LIBRARY_H
// my_library.h content
#endif /* MY_LIBRARY_H */

C

#ifdef MY_LIBRARY_H
#undef MY_LIBRARY_H
// my_library.h content
#endif /* MY_LIBRARY_H */

D

#define MY_LIBRARY_H
#include MY_LIBRARY_H
// my_library.h content
#undef MY_LIBRARY_H


Q41. What’s wrong with this definition when using a pre-C++11 compiler?
std::vector<std::vector<int>> thematrix;
  1. There’s nothing wrong with it.
  2. An std::vector cannot contain more std::vector containers as its elements.
  3. The correct syntax should be: std::vector[std::vector[int]] thematrix;
  4. >> is parsed as the shift-right operator, and thus results in a compile error.✔️
Q42. What is the statement below equivalent to?
sprite->x

  1. sprite.x
  2. sprite.*x
  3. (*sprite).x✔️
  4. *sprite.x


Q43. Consider a class named complexNumber. Which code will result in an equivalent object?
complexNumber(float real, float im)
: real_part(real),
im_part(im){}


A

complexNumber(float real, float im) {
this->real = real_part;
this->im = im_part;
}



B


complexNumber(float real, float im) {
this->real_part(real);
this->im_part(im);
}


C✔️

complexNumber(float real, float im) {
this->real_part = real;
this->im_part = im;
}


D

complexNumber(float real, float im) {
this->real_part = &real;
this->im_part = &im;
}



Q44. What is the result from executing this code snippet?

bool x=true, y=false;
if(~x || y){
/*part A*/
}
else{
/*part B*/
}
  1. Part A executes because the expression (~x || y) always results in true if y==false.
  2. Part B executes because the statement (~x || y) is invalid, thus false.
  3. Part A executes because ~x is not zero, meaning true.
  4. Part B executes because ~x is false and y is false, thus the OR operation evaluates as false.✔️
Q45. What would be the output of this code?
int32_t nums[3]={2,4,3};
std::cout << ( nums[0] << nums[1] << nums[2] );

  1. The output is the addresses of nums[0], nums[1], and nums[2], in that order, with no spaces.
  2. 256✔️
  3. 0
  4. 243
Q46. What is the output of this code?
float values[5]={0.54f, 2.71828f, 3.14159f, 5.499999f, 10.0f};
for(auto f:values)
printf("%i ",(int)(f+0.5f));

  1. 0.54 2.71828 3.14159 5.499999 10.0
  2. 1 3 4 6 11
  3. 0 2 3 5 10
  4. 1 3 3 5 10✔️
Q47. Which of the following STL classes is the best fit for implementing a phonebook? Suppose each entry contains a name and a phone number, with no duplicates, and you want to have lookup by name.

  1. std::priority_queue
  2. std::list
  3. std::vector
  4. std::map✔️



Q48. What does this program do?
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream file1("text1.txt", ios::binary);
ofstream file2("text2.txt", ios::binary);
file2 << file1.rdbuf();
}
  1. It renames text1.txt to text2.txt.
  2. It makes a directory called text2.txt and moves text1.txt there.
  3. It copies the contents of text1.txt into text2.txt – i.e., it makes a copy of text1.txt, named text2.txt.✔️
  4. It appends the contents of text1.txt into text2.txt – i.e., replaces the contents of text2.txt by the concatenation of text2.txt and text1.txt.



Q49. Which of the following is not a consequence of declaring the member variable count of my_class as static?
class my_class {
public: static int count;
}
  1. The variable cannot be modified by any part of the code in the same application or thread. However, other threads may modify it.✔️
  2. The variable exists even when no objects of the class have been defined so it can be modified at any point in the source code.
  3. The variable is allocated only once, regardless of how many objects are instantiated because it is bound to the class itself, not its instances.
  4. All objects that try to access their count member variable actually refer to the only class-bound static count variable.


Q50. What is the assumed type of a constant represented in the source code as 0.44?

  1. double✔️
  2. long float
  3. long double
  4. float


Q51. What is the output of this piece of code?
int8_t a=200;
uint8_t b=100;
std::cout<<"a="<<(int)a;
std::cout<<", b="<<(int)b;

  1. a=-56, b=100✔️
  2. a=-55, b=100
  3. a=200, b=-156
  4. a=200, b=100
Q52. What is an appropriate way of removing my_object as shown below?
my_class *my_object = new my_class();

  1. delete(my_object);✔️
  2. free(my_object);
  3. The garbage collector will destroy the object eventually.
  4. Exiting the scope will destroy the object.

Q53. What is the correct way to call the count member function for the object pointer called grades?
class my_array{
public:
int count();
}; // ... more members above
int main(){
my_array *grades = new my_array();
}; // ... more code above
  1. grades.count();
  2. my_array->count();
  3. grades->count();✔️
  4. my_array.count();


Q54. What would be the output of this code?
int i0=4, i1=6, i2=8;
int& nums[3]={i2,i0,i1};
std::cout<<nums[0]<<nums[1]<<nums[2];
  1. There is no output. The code causes a compiler error because nums is an array of references, which is illegal.✔️
  2. 846
  3. The output is the addresses of i2, i0, and i1, in that order, with no spaces.
  4. 468


Q55. What is child_t in this code?
typedef struct{
unsigned int age : 4;
unsigned char gender : 1;
unsigned int size : 2;
}child_t;
  1. It is a type defined as a structure with three unsigned fields initialized as age=4, gender=1, and size=2.
  2. It is a type defined as a structure with bit fields, with 4 bits for age, 1 bit for gender, and 2 bits for size.✔️
  3. This code causes a compiler error because the colon character is not allowed in struct definitions.
  4. It is a type defined as a structure with three arrays. The size and length of these arrays are age:int[4], gender:char[1], and size:int[2], all signed.


Q56. What is this expression equivalent to?
A->B->C->D
  1. A.B.C.D
  2. *A.*B.*C.*D
  3. &A.&B.&C.&D
  4. *(*((*A).B).C).D✔️
Q57. What does this function do?
auto buff = new char[50];
std::memset(buff,20,50);
  1. It declares a memory buffer named buff that starts at address 20 and ends at address 70.
  2. It sets all bits in the array named buffer from its element at index 20 to its element at index 50.
  3. It writes the value 20 in every memory address from buff to buff+49.✔️
  4. It declares a memory buffer named buff that starts at address 20 and ends at address 50.


Q58. Consider a class named CustomData. Which choice is a correct declaration syntax to overload the postfix ++ operator as a class member?

  1. CustomData& operator++();
  2. void operator++(CustomData);
  3. CustomData operator++(CustomData);
  4. CustomData operator++(int);✔️


Q59. You want to sort my_array, declared below. Which choice is the correct call to std::sort, using a lambda expression as the comparison function?
std::array<uint32_t, 50> my_array;



A✔️

std::sort(my_array.begin(), my_array.end(),
[](uint32_t a, uint32_t b) {
return a < b;
})


B

lambda(uint32_t a, uint32_t b){
return a < b;
}
std::sort(my_array.begin(), my_array.end(), lambda);


C

std::sort(my_array.begin(), my_array.end(),
lambda(uint32_t a, uint32_t b){
return a < b;
})


D


lambda(uint32_t a, uint32_t b){
return a < b;
}
std::sort(my_array.begin(), my_array.end(), &lambda);
Reference


Q60. Which choice is the most reasonable implementation of the function std::mutex::lock() by using std::mutex::try_lock()?


A✔️

void std::mutex::lock(){
while(!this->try_lock());
}


B

void std::mutex::lock(){
return (this->try_lock());
}


C

void std::mutex::lock(){
while(1)
this->try_lock();
}


D

void std::mutex::lock(){
while(this->try_lock());
}


Q61. What is the purpose of a destructor?

  1. It allows the programmer to write the necessary code to free the resources acquired by the object prior to deleting the object itself.✔️
  2. It deletes an object. One example of a destructor is the delete() function.
  3. It terminates a program. This may be achieved as a regular function call or as an exception.
  4. There are no destructors in C++.
Q62. Which STL class is the best fit for implementing a phonebook? Suppose each entry contains a name and a phone number, with no duplicates, and you want to have lookup by name.
  1. std::priority_queue
  2. std::map✔️
  3. std::vector
  4. std::list
Q63. What is the main difference between these two Functions?
std::mutex::lock()
std::mutex::try_lock()
  1. lock() has a higher privilege over try_lock(). This means that you have a better chance of acquiring a mutex with lock().
  2. Both attempt to acquire a lock, but lock() blocks if the mutex is not available, whereas try_lock() returns whether the mutex is available or not.✔️
  3. lock() enforces preemption, whereas try_lock() suggests preemption.
  4. If the mutex is not available, try_lock() returns with a corresponding code, whereas lock() snatches the mutex from the thread that currently has it.


Q64. What is one benefit of declaring the parameter as a const reference instead of declaring it as a regular object?
int median(const my_array& a)

  1. Actually, objects cannot 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.
  2. There are no benefits because a reference and an object are treated as the same thing.
  3. The const qualifier Forbids the code to modify the argument, so the programmer can rest assured that the source object will remain unchanged.✔️
  4. The argument is passed as a reference, so the Function receives a copy that can be modified without affecting the original variable.
Note: This one is similar to Q6, but focuses on the const keyword.


Q65. What is an include guard?
  1. a preprocessor directive that prevents inconsistent behaviors in lines that contain the #ifdef, #ifndef, or #elif directives
  2. a compiler option that prevents the user code from including additional libraries
  3. a preprocessor statement that prevents a source file from being included more than once in a project✔️
  4. a library that adds safety features such as mutexes, watchdog timers, and assertions to the project

Q66. What would be the correct declaration of a default constructor for a class named Sprite?

A✔️
Sprite();


B
void Sprite();

C
void Sprite();


D
Sprite();


Q67. What is the purpose of this line in a header file?
#pragma once
  1. to restrict the use of its contents to only one source file
  2. to tell the compiler that only one variable can be instantiated from the classes or types contained in this header file
  3. to help the compiler finish faster by assuring that only one compiler pass is neccessary for the code included in this header file
  4. to make the compiler parse that header file only once, even if it is included multiple times in the source✔️


Q68. What is a variable of type double?

  1. a 2-tuple
  2. an integer number
  3. a floating point number✔️
  4. a string with more than 255 characters


Q69. Which choice is a reason to specify the type of a pointer instead of using void *, which works as a pointer to any type?

  1. The compiler needs the data type to make sure that the pointer is not going to be used on illegal non-pointable types such as functions, labels, pointers, and reference.
  2. void * does not work for any type. The language does not allow assigning anything other than void to a pointer to void *.
  3. The compiler needs the data type to know how much memory to allocate for the pointer, because different data types require different pointer lengths.✔️
  4. Yes, it causes a compiler error because one field is defined as having a size of 0.


Q70. What is wrong with this piece of code?
#include <iostream>
char str[20];
int main(){
std::cout << "What's your name? ";
str << std::cin
std::cout << "Hello, " << str;
return 0;
}

  1. The main function is supposed to have a void return type.
  2. std::cin and std::cout are invalid. The correct names for the character input and output streams are cin and cout.
  3. The address of str is supposed to be used. That is &str instead of str.
  4. The input operator flow is inverted. it should start from std::cin and then flow (>>) into str.✔️
Q71. When placed in a valid execution context, which statement will dynamically allocate memory from the heap for an integer of value 11?

  1. int anInt = new int(11);
  2. int* anInt = new int[11];
  3. int anInt = new int[11];
  4. int* anInt = new int(11);✔️
Q72. Which choice best describes the type long?

  1. an integer number of at least 32 bits✔️
  2. a string with more than 255 characters
  3. a pointer
  4. a 64-bit floating point number


Q73. Which of the following types has the closest functionality to a class?
  1. struct✔️
  2. union
  3. enum
  4. namespace


Q74. Given these records in a map, how will you update the value for the key "Sinead" to 22?

  1. marks["Sinead"] = 22✔️
  2. marks["Sinead"].22
  3. marks["Sinead"] -> 22
  4. marks["Sinead"].value = 22
Q75. Why can the std::sort receive a function object as one of its parameters?

  1. The std::sort function is a template. The programmer is free to enter the sorting algorithm in a function object as an argument.
  2. Actually, std::sort takes only one argument, which is the container to be sorted.
  3. std::sort operates on a template container. The compiler does not know how to relationally compare the values it contains, so a function must be provided to do the comparison.✔️
  4. std::sort will use the parameter function as an error handler. The function will be called if an error occurs.
Q76. What will happen when you execute this code snippet?
#include <iostream>

int main() {
float a = 5.51;
int b = static_cast<int>(a);
std::cout << b;
}

  1. 6 will be printed on standard output, with no compilation warnings generated.
  2. 5 will be printed on standard output, with no compilation warnings generated.✔️
  3. 6 will be printed on standard output, with compilation warnings generated.
  4. 5 will be printed on standard output, with compilation warnings generated.
Q77. Which access specifier does not allow class members to be accessed from outside the class, but allows them to be accessed by derived classes?

  1. guarded
  2. protected✔️
  3. public
  4. private
Q78. What is true about the variable named ptr?
void *ptr;

  1. That declaration causes a compiler error, as pointers must specify a type.
  2. It is a pointer to a value with no specific type, so it may be cast to point to any type.✔️
  3. It is a pointer to a void function
  4. It is a pointer initialized at NULL.
Q79. What is a valid definition for a function named get_length that returns the length of a null-terminated string?
int get_length(char *str);


1. :✔️
int get_length(char *str){
int count=0;
while(str[count++]);
return count-1;
}


2. :
int get_length(char *str){
int count=0;
while(str!=NULL){
count++;
str++;
}
return count;
}


3. :
int get_length(char *str){
int count=0;
while((*str)++)
count++;
return count;
}


4. :
int get_length(char *str){
int count=0;
while(str++)
count++;
return count;
}


Q80. What is this statement equivalent to?
sprite->x
  1. sprite.*x
  2. (*sprite).x✔️
  3. *sprite.x
  4. sprite.x

Q81. In which scenario would you want to specify the type of a pointer instead of using void?

  1. void does not work for any type. The language does not allow assigning anything other than void to a pointer to void.
  2. The compiler needs the data type to caculate the length of the pointed data (for reading and writing) and to calculate increments and decrements to the pointer.✔️
  3. The compiler needs the data type to make sure that the pointer is not going to be used on illegal non-pointable types such as functions, labels, pointers, and references.
  4. The compiler needs the data type to know how much memory to allocate for the pointer, because different data types require different pointer lenghts.
Q82. The default executable generation on UNIX for a C++ program is _
  1. a.exe
  2. a
  3. a.out✔️
  4. out.a
Q83. What will be the output of the following program?
#include<iostream>
using namespace std;
int main(){
int a=1;
cout<<(a++)*(++a)<<endl;
return 0;
}
  1. 1
  2. 2
  3. 3✔️
  4. 6
Q84. What does "c" stands for in cout and cin.
  1. compiler
  2. console
  3. character✔️
  4. standard namespace
Q85. What is the use of tellp ()?

  1. Current Input Pointer position
  2. Current Output Pointer position✔️
  3. Last Input Pointer position
  4. Last Output Pointer position

Q86. What is callback function?

  1. Pointer for a pointer
  2. Pointer for a function✔️
  3. function for a pointer
  4. function for a class

Q87. What is a correct syntax to output "Hello World" in C++?
  1. cout << "Hello World";✔️
  2. System.out.println("Hello World");
  3. print("Hello World");
  4. Console.WriteLine("Hello World");
Q88. What is the meaning of base class in C++ ?

  1. It inherit other class
  2. It has a pointer variable
  3. It is the first class declared
  4. Another class got inherit from this class✔️
Q89. Size of C++ objects are expressed in terms of multiples of the size of a _ and the size of a char is _ .
  1. char, 4
  2. float, 8
  3. int, 1
  4. char, 1✔️
Q90. Implementation dependent aspects about an implementation can be found in
  1. <numeric>
  2. <limit>
  3. <limits>✔️
  4. <implementation>
Q91. What is a default constructor?
  1. a constructor that can be used with no arguments✔️
  2. a contructor that does not have a return value
  3. a constructor that is used by multiple classes
  4. a constructor that initializes all members of a class
Q92. When protecting a header file, why would you use ‘#pragma once’ instead of ‘include’ guard?

  1. There is no reason to choose because they serve different purposes
  2. An include guard uses a macro to achieve single inclusion, but the compiler cannot prevent the programmer from defining that macro elsewhere, which would result in no inclusion at all defining that macro elsewhere, which would result in no inclusion at all✔️
  3. ‘#pragma once’ guarantees that the header code will never be changed because it is enforced by the compiler
  4. Include guards refer to the header file in the file system, not to the code, so they are not helpful if the header file exists more than once in a project. This is not a problem with ‘#pragma once’
Q93. Which of the following statement is valid?

  1. We can create new c++ operator.
  2. We can change the precedence of the c++ operator.
  3. We can not change the operator templates.✔️
  4. We can change the associativity of the c++ operators.
Q94. Which of the followings is/are automatically added to every class, if we do not write our own?

  1. Copy Constructor
  2. Assignment Operator
  3. A constructor without any parameter
  4. All of the above✔️
Q95. The if-else statement can be replaced by which operator ?

  1. certain structure
  2. choosing structure
  3. selective structure✔️
  4. None of the Above

Q96. Does this code cause a compiler error? If so, why, and if not, what is child_t?

typedef struct{
unsigned int age : 4;
unsigned char gender : 1;
char : 0;
unsigned int size : 2;
}child_t;
  1. Yes, it causes a compiler error because the colon character is not allowed in struct definitions.
  2. No, and child_t is a type defined as a structure with bit fields. It has 4 bits for age and 1 bit for gender in the first byte, and 2 bits for size in the second byte.✔️
  3. Yes, it causes a compiler error because there is an unnamed field.
  4. Yes, it causes a compiler error because one field is defined as having a size of 0.


Q97. What is this expression equivalent to?

  1. A->B
  2. *(A.B)
  3. B=A
  4. (*A).B✔️
  5. &A.B
Note: a simpler variant of the question below.


Q98. Other than shifting bits to the left, what is the << operator used for ?
  1. shifting characters to the left in a string.
  2. inserting characters into an output stream like std::cout.✔️
  3. comparing floating point numbers as less-than.
  4. assigning a variable to a reference.

Q99. How many categories of iterators are there in C++ ?
  1. 4
  2. 3
  3. 7
  4. 5✔️
تعليقات



حجم الخط
+
16
-
تباعد السطور
+
2
-