Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » List of Companies » Walmart Technical Questions

Walmart C++ Interview Questions

Location: Bentonville, USA
Experience Required: Any
Profile: Senior C++ Developer
Degree: Any Degree (Computer Science)

1. The programmer has decided to store objects of a user-defined type(a structure) in an unordered_set. Which of the following are steps that must be taken in order for this to work properly?

A. The structure will have to define a default constructor
B. The structure will have to overload operator<() so that the elements can be stored in the proper palce within the collection.
C. The structure will have to create a specialization of std::hash for the user defined type.
D. The structure will have to overload operator==() in order for this type to be supported by this collection.
E. The structure will have to overload operator() so that elements may be locatedin the collection.

2. Which of the following are differences between signed and unsigned variations of the same integer type in a 2's complement implementation of ASNSI C?

A. The range of the signed and unsigned variabtions of the same integer type are equivalent in size and numberic maximum and minimum.
B. The range of the unsigned variation of an integer type is twice that of the signed variation.
C. A negative value, expressed as a signed integer, will be expressed as a positive value greater than the maximum value of the signed integer, if expressed as in unsigned integer
D. They have the same size, but the signed variation range is centered around 0 (zero), and the unsigned variation range has a lower bound of 0 (zero).
E. The representation of a signed integer has one additional bit for the sign.

Question 3. Which of the following correctly identify the output of executing the C++ code below?


template<class T>
void stripConst(T arg)
{
typename std::remove_const<T>::type new_arg;
if(std::is_const< decltype( new_arg ) >::value )
    std::cout<< "Type of new_arg is const"<<std::end;
else
    std::cout<< "Type of new_arg is not const" << std::endl;
}
int main()
{
 stripConst( "Blinkin" );
 stripConst( 676 );
 stripConst( 3.14 );
}

A. Type of new_arg is not const
  Type of new_arg is const
  Type of new_arg is const
B. Type of new_arg is const
  Type of new_arg is const
  Type of new_arg is const
C. Type of new_arg is not const
  Type of new_arg is not const
  Type of new_arg is const
D. Type of new_arg is const
  Type of new_arg is not const
  Type of new_arg is not const
E. Type of new_arg is not const
  Type of new_arg is not const
  Type of new_arg is not const

4. Given the C++ class difinition and corresponding application code below, which of the following statements are true (the answer choices consider the presense or absense of Line D?


class MoverAndShaker
{
public:
	MoverAndShaker(std::string s = "", int i=0) {...}; //Line A
    MoverAndShaker(MoverAndShaker * rhs) {..;};        //Line B
    MoverAndShaker(MoverAndShaker const & rhs) {...};  //Line C

    //NOTE: this Line is referred to as existing or not in the answer choices
    //MoverAndShaker(MoverAndShaker &&rhs) {...};      //Line D  
};

int main()
{
MoverAndShaker mas1("Carlos", 10);
MoverAndShaker mas2(mas1);                      //Line X
       
MoverAndShaker mas3 = std::move(mas1);          //Line Y
MoverAndShaker mas4(MoverAndShaker("Phil", 30));//Line Z
//the rest of the application has been omitted
}

A. If Line D is commented out (does not exist) in the class definition as shown, then Line Y will result in the constructor on Line C being called. And, if Line D is not commented out (exists), then Line Y will result in the constructor on Line D begin called.
B. If Line D i snot commneted out (exists), and properly implments move semantics, and an application stores and uses objects of this type with STL containers, the application might execute slower.
C. Line Z will result in the constructor on Line C being called regardless of whether or not the constructor on Line D is commented out (whether it exist or not).
D. If Line D is not commented out(exists), and properly implements move semantics, the application code after Line Y can assume that the object mas1 is intact.
E. If Line D is commented out (does not exist) in the class definition as shown, then Line Y will result in a compiler error.

5. Which of the following correctly identify the results of building the C++ code below?


class SomeClass
{
protected:
	int data;
	friend class AnotherClass;
};

void SomeFunc(SomeClass sc)
{
sc.data=5;
}

class AnotherClass
{
public:
	void Another(SomeClass sc)
    {
        sc.data = 25;
    }
    friend void SomeFunc(SomeClass sc); 
};

int main(void)
{
SomeClass sc;
SomeFunc(sc);
cout<<sc.data;
}

A. The build will be successful, and the proram will display an output of "5" when it is executed.
B. Compiling generates an error because main() is not allowed to access the protected memebers data of SomeClass.
C. Compiling generates an error because AnotherClass is not allowed to declare SomeFunc() as a frind as it is already a friend of SomeClass.
D. Compiling generates an error because Another() of AnotherClass is not allowed to access the protected member data of SomeClass.
E. Compiling generates an error because SomeFunc() is not allowed to access the protected member data of SomeClass.

6. Which of the following segment of C++ code contains problems?

A.
for(char idx=0; idx<250; idx++)
{
cout<<"hello world<<endl;
}

B.
int getLength()
{
return 10;
}
int size = getLength();
char message[size];

C.
int numberator, denominator;
numerator = 10.0;
denominator = 3.0;
float = quotient / denominator;

const int size = 10;
char message[size];

D.
bool ok = true;
if(!ok)
{
cout<<"not ok"<<endl;
}

7. Which of the following are valid statements regarding the ANSI C pointer ptr below?

A. ptr must refer to desc.
B. Incrementing ptr will cause misalignment between ptr and desc.
C. ptr may point to any descriptor elsewhere in memory.
D. desc can not be modified throught ptr. desc may be modified throught ptr.

8. Which fo the following correctly descibe the ANSCI C declaration below?

char *p = "Hello";
char * const q = "Hello";
const char *r = "Hello";
char const *s = "Hello";

A. q can be made to point to another string literal.
B. r is an non-constants pointer ot a string literal.
C. p is defined as a non-constant pointer to a string literal.
D. s is a constant pointer to an non-constant string literal.
E. q is a constant pointer to a string litera.

9. Which of the following statements correctly describe the ANSI C program below?


#include<stdio.h>

union u
{
  short int no
  char ch[2];
};
int main(void)
{
 union u uu;
 uu.no = 35;
 return 0;
}

A. The size of variable uu would be 16 bytes.
B. Assigning a value of 40 to uu.no would change the value of uu.ch[0].
C. Assigning a value to any union element changes the value of other union elements.
D. The size of variable uu would be 8 bytes.
E. Assigning a value of "40" to uu.ch[0] will change the value of uu.no

10. Which of the following properly define an ANSI C function foo() which accepts as parameters an integer, an unsigned integer and a pointer to a character, and returns an unsigned integer?

A. (int x, unsigned int y, char *m) foo(unsigned int k) {...}
B. foo{unsigned int r, int h, unsigned int j, char *g} (...)
C. unsigned int foo(int a, unsigned int b, char *c) {...}
D. unsigned int foo(char *q, unsigned int x, int i) {...}
E. (unsigned int) foo, int a, unsigned int z, char *r{...}