Hi All,
It is actually not possible to list out a set of questions and tell that your interviewer will ask questions from that set only, still it is my small initiative, to list out some frequently asked c++ questions.
My request to all readers, please add questions on comment, if I have missed something which you feel is very important.
My aim is whenever anyone wants to go for interview. He/She should not struggle much for c++ language related questions. He/She can just visit here and prepare best for c++ interview questions.
Array -
- Why is it recommended to not use array polymorphically, as function parameter? Hint - look at more effective c++ item 3.
- How to implement dynamic array? Code - 01,
- How you will pass 2-D array to a function argument? Code - 01, 02, 03,
Pointers and reference -
- What is the difference between using pointer and reference? Hint - look at more effective c++ item 1.
- Reference
- Returning reference vs value from overloaded assignment operator. Hint - focus on how many time we will invoke constructor and destructor.
- Pointers
- We have two functions - void foo(int a); and void foo(char *ptr); and my client code calls it like - foo(NULL); // which foo it supposed to call? Hint - ambiguity, instead use nullptr.
- What is smart pointers? implement it. Hint - understand how auto memory type works, what is RAII, use smart pointers in place of raw pointers, so that you will not fall into memory leak condition even exceptions are thrown. Look at more effective c++ item 9, 28.
- If we have pointer to array like - int *pInt = new int [4]; and I delete pointer after increment it, like - ++pInt; delete[]pInt; what will happened? Hint - read about control blocks, array of memory have.
- What is auto_ptr? Hint - look at more effective c++ item 28, Code 01, .
- Why is it recommended to not pass auto_ptr by value? Hint - look at more effective c++ item 28.
- Why we should return by reference, while implementing operator *, in auto_ptr? Hint - look at more effective c++ item 28.
- What is std::unique_ptr? What is the difference between std::unique_ptr and auto_ptr? Hint - look at effective modern c++ item 18.
- What is shared_ptr? Hint - look at more effective c++ item 29
- In c++11, can we have shared_ptr pointing to an array? Hint - No, if u want, give your own delete function. Also we can say this is one of the drawback of the smart pointer as they can not detect difference between pointer pointing to object or pointing to an array of object.
- what is week pointer ?
Casting -
- How many type of casting do we have in c++? Hint - look at effective c++ item 27.
- When you will use dynamic_cast? real life example.
- Tell a condition where you cannot use static_cast.
- Why is it recommended to use C++ style of casting over C style of casting in CPP code implementation? Hint - look at more effective c++ item 2
- What are basic rule of user defined conversion? Hint - look at more effective c++ item 5
- Why is it recommended to minimize casting as much as you can? Hint - look at effective c++ item 27.
String
- Split a string, on the basis of some delimiter. Code - 01,
C++ general questions -
- What is size_t type? Is it platform dependent? Hint - look at effective c++ item 1.
- What is preferred among these -> a. pass-by-value b. pass-by-reference, c. pass-by-reference-to-const? Hint - look at effective c++ item 20.
- What if you don't return anything from overloaded assignment operator? Hint - you will not be able to perform -> a = b = c =d; For more details look at effective c++ item 10.
- What is the difference between structural programming and OOPS?
- What is the difference between function overloading and function overriding?
- What is name mangling? Is it there in c?
- How you will call a c function in c++ code? or How to combine c and c++ code?
- What is RTTI? Tell some real time use or RTTI. Hint - look at more effective c++ item 24, Code 01, 02,
- What is a mutable data member? Hint - look at effective c++ item 3.
- Namespace
- What problem does the namespace feature solve?
- What is anonymous namespace?
- If we are declaring a friend function, what should be the scope of that function? global? or class specific? what is the good practice?
- what is functor?
- Why is it recommended to prefer, ststic, inline, and enums over #define? Why we should bot replace functions with #define? Hint - look at effective c++ item 2
- Why is it recommended to move non-local object to it's own function? or If you have more then one static object, and they have to get construct in some order, how you will make sure, that they get constructed in defined order? Hint - look at effective c++ item 4.
- RAII (resource acquisition is initialization)
- What is RAII? Hint - look at effective c++ item 13.
- How copying behavior works in RAII classes? Hint - look at effective c++ item 14.
- Why to provide access to raw pointer in RAII class? What is explicit and implicit conversion in this case and which one is preferred? Hint - look at effective c++ item 15.
- What is the problem in mentioned function signature -> process(shared_ptr<className>(new className), priority()); Hint - look at effective c++ item 17.
- What is cross DLL problem? Hint - look at effective c++ item 18.
- When compiler perform type checking, during compile time or during run time? Hint - look at effective c++ item 41.
- What are traits classes? Why we use them? Hint - look at effective c++ item 47.
- What is array to pointer decay rule?Are they same - void myFunc(int param[]); and void myFunc(int* param); Hint - look at effective modern c++ item 1.
- Extension to previous question, what is function to pointer decay rule? Hint - same as mentioned in question 22.
- What is the "volatile" in c++?
- Compiler
- How to disable warnings in c++?
- Can I use dll build in 2010 in the executable build in 2015?
- add
Class -
- List out the compiler generated functions for any class. Hint - look at effective c++ item 5.
- How you can restrict compile to insert default functions? Hint - there is also another way in c++11, see c++11 questions and also look at effective c++ item 6.
- What is rule of 3?
- Write a string class or implement your own string class similar to standard string class. Hint - they want to see how you are writing a class which has a pointer (say char *pString). focus on overloaded assignment operator and copy constructor while writing your code. CodeEx01.
- How you will handle, self assignment in overloaded assignment operator? Hint - look at effective c++ item 11.
- Write the syntax of this pointer. How it looks like? Hint - it is different for const and non const functions.
- What will happened when you will delete this pointer? Hint - undefined behavior.
- What is object slicing and how to avoid it? Hint - loot at effective c++ item 20, also look at link01.
- Initialization
- When is it mandatory to use initialization List in C++?
- Can a class have a reference variable? If yes, then how you will assign value to reference variable? Hint - use initialization list.
- How you will initialize const data member of a class? Hint - look at effective c++ item 2.
- Friend
- Tell some real scenarios where you have used friend functions. Hint - to overload << operator. CodeEx01.
- How to write friend class?
- How to instantiate a derived class object, whose base class ctor is private? Hint - use friend function.
- Create a singleton class, which is singleton for all, but one specific class can create any number of objects of that singleton class. Hint - use friend function.
- Static
- How you will initialize static data member of a class? Hint - look at effective c++ item 2. Code - 01, const static,
- What if I declare static data member in header file, and define it there itself? Hint - compilation error. Code - StaticInHeader01, StaticInHeader02
- What is the use of static data member? Hint - it will be visible from all instance of that class. Code 01, 02, 03,
- What is the size of empty class?Why at all we create empty class, what is the purpose? What is empty base class optimization (EBO)? Hint - look at effective c++ item 39.
- Inline functions
- What is inline functions? Detail out the drawbacks and advantage of inline functions. Hint - look at effective c++ item 30.
- What is implicit and explicit, inline function declaration?
- Can we declare constructor or destructor as inline function? If no, why? Hint - look at effective c++ item 30.
- Can we create function pointer of an inline function?
- What is composition? How you will implement it? Hint -
Constructor -
- Can we throw a exception from constructor?
- What is copy constructor?
- What is the difference between deep and shallow copy? Hint - look at effective c++ item 12
- When to use copy constructor, in private?
- How to inform client that construction of object has failed? Hint - we can set some boolean value isSuccess to false and poisoned the data.
- Can we define constructor as virtual function? Hint - no
- What is a default constructor? Is that mandatory that compiler will provide default constructor every time if you missed it in your class?
- How to restrict compiler from creating default constructor for us? Hint - look at more effective c++ item 4.
- Tell some scenarios where we should declare default constructor (zero-argument constructor). Hint - when you are creating array of object and also look at more effective c++ item 4.
- What is a conversion constructor? Hint - single argument constructor will act like, implicit converter, look at more effective c++ item 5.
- What is explicit keyword in constructor? Hint - use to solve problem discussed at previous question, look at effective c++ item 24 and more effective c++ item 5.
- What will happen when you pass pointer in copy constructor? Hint - not good idea as pointer can be a null pointer. Hint - look at more effective c++ item 1
Destructor -
- True or false -> "If base class destructor is virtual, then compiler will insert virtual destructor into derived class."
- Can we throw a exception from destructor? or, What will happend if exception occur in destructor? Hint - look at effective c++ item 8 and more effective c++ item 11.
- Why do we need virtual destructor? Hint - look at effective c++ item 7.
- Is it a good idea to have virtual destructor in base class, when I am inheriting it as private inheritance in by derived class?
- Why we declare destructor as pure virtual destructor? Can pure virtual destructor have body? Hint - look at effective c++ item 7.
Operators and operator overloading -
- What are conversion operators, and why you should not use them until you have to? Hint - look at more effective c++ item 5.
- What is pre-fixed and post fixed operator? overload Increment and Decrements Operator. Hint - look at more effective c++ item 6. This is also a perfect example when it make sense for a function to return const object, and not reference.
- In for loop is it ok to use post fix operator ? or Why it is recommended to use prefix over post-fix? Hint - look at more effective c++ item 6.
- Why is it not recommended to overload &&, || , dot (.), comma (,) .. few other as well, operators? Hint - look at more effective c++ item 7. Recommendation - if you don't have good reason to overload any operator don't overload it.
- Overload + operator for complex number. It should work for all mentioned case -
- complex A, B, C;
- c = A + B;
- int i = 10;
- C = A + i;
- C = i + A;
- Hint - look at effective c++ item 24.
- overload << operator for your class. Code - 01, 02,
- add
Memory management -
- How many storage Classes do we have? Hint - link01.
- How malloc works? Code - 01, 02, 03, 04,
- Can we crate an object from new and delete it from free ?
- Overload operator new and delete in global and class scope? Hint - look at more effective c++ item 27.
- How free will know the size of object (how much memory it has to free)?
- Tell the usage of new, operator new, placement new, delete, operator delete, new[] and operator new[], in c++. Hint - look at effective c++ item 16 and more effective c++ item 8. Code - Placement new (01,)
- How delete[] will know how many objects it has to delete? Hint - look at effective c++ item 16.
- Tell some scenarios where you will use placement new.
- What is std::new_handler and set_new_handler function? Hint - look at effective c++ item 49.
- When it make sense to to overload new and delete operators? Hint - look at effective c++ item 50.
- Write class specific new and delete operators. Hint - look at effective c++ item 51 and 52.
- Justify statement, "if you have written placement new then you should write placement delete". Hint - look at effective c++ item 52.
Inheritance and Virtual functions (or run-time polymorphism) -
- Inheritance
- How many types of inheritance are exist in c++? Hint - Multiple, Multilevel, Hybrid, etc..
- Justify statement - "if it is inheritance follow is-a model strictly". Hint - look at effective c++ item 32.
- Can we implement inheritance in struct? Hint - Yes
- How to make a class, abstract class? What do you mean by abstract class? How you will handle virtual, non-virtual and pure-virtual functions of your base class, into your derived class? Hint - look at effective c++ item 34 and 36
- What is Private Inheritance? When we will use it? Hint - look at effective c++ item 39.
- What are the differences between private, public and protected inheritance?
- When should you use multiple inheritance? Hint - look at effective c++ item 40.
- Why run-time polymorphism is very costlier in multiple inheritance? Hint - look at more effective c++ item 24
- Describe diamond problem? How you will solve it? Write constructors of all classes.
- What is virtual inheritance?
- Polymorphism (Virtual)
- What is virtual function and what all things will happens when u create a function as virtual function? Hint - vtbl and vptr.
- Why is it recommended to avoid hiding inheritance names? Or names in the derived class will hide the name of base class, under
"public inheritance", this is wrong behavior, as public functions of
base has to be accessible at any cost.? Hint - In case of overloaded functions. One is virtual and other is
non-virtual. Or both are non-virtual. Avoid compilation error in derived
class by using derivatives. For more info look at effective c++ item 33.
- Can we give definition to pure-virtual function? Hint - look at effective c++ item 34.
- We can give by default value to our function parameter, but in the case of inheritance, how it will behave if I give different. by default value, to same function parameter while function overriding? Hint - look at effective c++ item 37.
- What is the difference between template class (implicit interface or compile time polymorphism) and virtual class ( explicit interface)? Hint - look at effective c++ item 41.
- How we were achieving dynamic binding without virtual? Hint - through functions pointers, in call back function.
- What will happen if I call virtual function, from constructor or destructor? Hint - look at effective c++ item 9.
- What is vtbl? will derived class's vtbl hold the function pointers of base class's virtual function?
- How vptr pointer looks like? internals (or say syntax).
- Can we declare inline virtual functions? Hint - look at effective c++ item 30 and more effective c++ item 24
- What will happened when you have run-time polymorphism but you didn't declare destructor as virtual and delete base class pointer?
- What if my derived class has virtual function in private? Ans. Hint - also look at effective c++ item 35, code.
- What is the cost of virtual functions and RTTI? Hint - look at more effective c++ item 24.
- add
Templates -
- Can template class contain virtual or pure-virtual functions ? Hint - Yes.
- Can a template class contains template virtual function? Hint - No.
- Detail out all usage of typename. What is nested dependent name? Hint - look at effective c++ item 42.
- What is the difference between typename (Hint - need not to be a class)and class (Hint - for classes and structures)in template programming ? Hint - look at effective c++ item 42.
- Why we cannot access template base class's function directly in template derived class? Hint - in the derived class templates, refer to names in base class templates via (this pointer) -> or by using using declarative or via scope resolution operator. For more details look at effective c++ item 43.
- What is template specialization? When we use it? Hint - look at effective c++ item 43.
- Tell drawback of using template? or What is code bloat? Hint - look at effective c++ item 44.
- How to implement generalized copy constructor? Hint - look at effective c++ item 45
- Justify statement - "implicit conversion via constructor call is not considered during template argument deduction". Hint - Rational<int> result = first * 2; //error, extension to question number 5 of operators and operator overloading (mentioned above) look at effective c++ item 46.
- Can we give definition to friend function (non-member function) inside the class? Hint - look at effective c++ item 46
- What is template meta-programming?
Exception handling -
- What exception safe functions guarantee you and how you will achieve it? Hint - look at effective c++ item 29.
- What will happened between try and catch block ? Hint - stack-unwinding
- What is Stack Unwinding in C++?
- How to catch all exceptions?
- List out some of standard exceptions. Hint - look at more effective c++ item 13.
- How does throwing and catching exceptions differ from using setjmp and longjmp?
- How you will deal a situation where your constructor has potential to throw an exception? Remember if constructor throws exception, it will become half constructed object and compiler will not invoke destructor on half constructed object. Hint - look at more effective c++ item 10.
- What are difference between function call and catch statement? Hint - look at more effective c++ item 12.
- Why throwing by copy will create 2 objects, and create object slicing problem? Hint - look at more effective c++ item 12 and 13.
- What is re-throw? Hint - it will solve the issue mentioned in problem #8, look at more effective c++ item 12.
- Why is it not recommended to catch exception by pointers or base class type and recommended to catch it through reference? Hint - look at more effective c++ item 12 and 13.
- Is implicit conversion allowed during catch the exception? Hint - look at more effective c++ item 12.
- What is exception specification? Hint - loot at more effective c++ item 14.
- What will happened if function void foo() throw(); actually throw exception? Hint - undefined behavior could lead to core dump. Code - 01,
- How you can set your own unexpected exception handler? Hint - use set_unexpected(UserDefinedFunctionName) , loot at more effective c++ item 14.
- What is the cost of exception? Hint - look at more effective c++ item 15.
- Implement no-throw swap, function. Hint - look at effective c++ item 25
I/O -
- Print the last K lines of an input file.
Achieve efficiency in c++
- Know about 80-20 rules. Hint - look at more effective c++ item 16.
- What is lazy loading and how we will implement that? Hint - look at more effective c++ item 17.
- What is Eager evaluation, how to implement it in c++? Hint - look at more effective c++ item 18.
- What is the cost of temporary object? In what all scenarios they will get created? How you can reduce it? Hint - look at more effective c++ item 19.
- What will happen when you pass char array[] to string parameter? Hint - look at more effective c++ item 19.
- Will temporary object creation take place during implicit type conversion? If yes, then how you can avoid that? Hint look at more effective c++ item 21.
- What is return value optimization? Hint - look at more effective c++ item 20.
- How we can minimize the compiler dependencies between files? Hint - look at effective c++ item 31
Techniques (or jugad, in hindi) in c++
- Can we have virtual constructors in c++? no! Hint - you can think of factory method design pattern as virtual constructors, and we can mimic them here, to have a feel of virtual constructors (have clone functions). look at more effective c++ item 25. Code VirtualConstructorError, VirtualConstructorThroughClone,
- How to make non-member function, act like virtual function? Hint - take base class object as function parameter, and perform public operation through that object, while will intern do things polymorphically, for more look at more effective c++ item 25. Code - NonMemberAsVirtual,
- How can you implement your class such a way, it creates 0 or 1 object only? Or How to limit the number of objects of your class? Hint - if you make constructor private, no object shall be created by client or think of singleton design pattern, look at more effective c++ item 26. Code SingleObj, K-NumOfObjectsOnHeap, K-NumOfObjectsOnStack, K-NumOfObjectsOnHeapNoOneInherit, K-NumOfObjectsOnHeapOutSideClass, CountingBaseClass
- How to make a class like no one can inherit it? Hint - look at effective c++ item 39 more effective c++ item 26 + this link. Code - NoInheritance,
- How to make a class which can only create its object on heap (only through new)? If I try to create simple object on stack, it should give me compilation error. Hint - look at more effective c++ item 27, other link, Code OnlyInHeap,
- Once you achieve heap based object implementation, you ristrict your class to being inherited or be part of other class as composition, how would you solve this problem. Hint - look more effective c++ item 27. Code - ,
- How to create a class which can allow object creation only on stack not on heap (aposit of question-5). Hint - look at more effective c++ item 27. Code - OnlyInStack,
- After achieving object creation only on stack, you will face same issue, like what will happened in the case of inheritance, will client be able to create derived class object on heap?
- Use of proxy classes. Hint - look at more effective c++ item 30.
- How to overload operator [][], to display two dimensional array? Code - OverloadOperator
- How to detect operator [], is getting used to display a value or update the value? Code - ReadOrWrite
- int arr[MAX];
- cout << arr[0] // display
- arr[0] = 10 // update
- How you can tell operator [] is getting used for read or write operation? Hint - look at more effective c++ item 30.
- How you can make function virtual, in the respect to more then two objects? Hint - look at more effective c++ item 31
- What is p-impl idiom? Hint - look at effective c++ item 25 and 29.
- Detail out the alternatives to virtual function. Or What is non-virtual interface idiom (NVI)? Hint - look at effective c++ item 35.
Call backs
- What do you understand by function pointers? How to declare and use them? Code - 01,
- Can we call two different function, who has same function signature through one function pointer? Code - 01,
Good practice to follow -
- Make interface easy to use correct and hard to use incorrect. Hint - look at effective c++ item 18.
- How to design your class? Hint - look at effective c++ item 19.
- Declare data member in private. Hint - look at effective c++ item 22
- If you are library developer, exposing non-member , non-friend function to client code, will give you more flexibility. Hint - look at effective c++ item 23.
- Postponed variable definition as long as possible. Hint - look at effective c++ item 26.
- Don't return the handler to any private data member of a class. It will also help you in multi-threading environment, specially when you want to put mutex on that data member. Hint - look at effective c++ item 28.
C++11 -
- General c++11 concepts.
- What is uniform initialization in c++ 11?
- How initializer_list<T> works, and when we use it? Code 01,
- what is move, how it works?
- List out all default compiler generated functions in c++11.
- Write the function signature of move. Hint code 01, 02,
- Will copy constructor gets created if you have defined move constructor? Or how to make your object not copyable?
- Will move constructor gets created if I create copy constructor? Reverse of previous question
- How auto works?
- What is auto keyword in c++ 11? How does it useful? Hint - look at effective modern c++ item 5.
- How compiler detect the type of auto? How auto type detection is different from template type detection? Can template type detection, detect initializer_list? Hint - look at effective modern c++ item 2
- How type detection are different in below mentioned cases -
- Case - 1
- const char name[] = "R. N. Briggs";
- auto arr1 = name;
- auto& arr2 = name;
- Case - 2
- void someFunc(int, double);
- auto func1 = someFunc;
- auto& func2 = someFunc;
- What is the difference between below mentioned two loops, when we use what? -
- for(const auto& i: arr) {...}
- for(auto i: arr) {...}
- Hint - look at the output of auto by value and auto by reference programs.
- Why is it not recommended to use auto with std::vector<bool> return type? What is explicit typed initializer idiom? Hint - effective modern c++ item 6.
- Why we use bind in c++?
- What is std::function? Hint - a new way of writing function pointers. Code 01, 02,
- How constexpr works?
- Is constexpr always guaranteed to be on compile time?
- Can we use delete keyword, to indicate compiler not to generate default functions?
- How to force compiler to generate its default function? Hint use - default keyword.
- Can I delegate other constructor from any constructor in c++11? Hint - use initialization list , code 01,
- What is enum class? How it works? Hint - added scope resolution operator.
- How to make my class, such that no one can inherit from it? Hint use final keyword.
- What you we mean by final virtual function ?
- Lambda expression
- How we can remove functor? Hint - by using Lambda expression
- How to capture all local values in lambda? Hint - use [=]
- How you will capture all local values by reference in lambda? Hint - use [&]
- How you mention the return type of lambda? Hint - []() -> bool {}
- Literals
- Can we have user defined Literals? For ex - height = 3.4cm; hre cm is user defined literals. Hint - usae operator""
- What is the limitations of c++ literals? Hint - it works with few primitive data types.
- loops
- Write enhanced version of for loop.
- for_each
- override keyword
- When to use override keyword?
- What problem override keyword solves, which we has in c++03?
- universal reference
- Universal reference
- What is R-value reference? What is the difference between R-value reference and universal reference? Hint - Code 01,
- Can we overload function on the basis of L-value reference and R-value reference?
- What is perfect forwarding? Hint - we use it with template, and forward to other function. std::forwared<T>(arg), Code 01,
- What is the difference between std::forwared and std::move? Hint - code 01,
- When to use remove_refence? And how it works? Hint - Code 01,
- nullptr
- What is the difference between NULL and nullptr?
- add
- Template
- How compilier detect template types in below mentioned 3 conditions - (Hint - look at effective modern c++ item 1)
- Parameter type is a pointer or reference type.
- Parameter type is a universal reference.
- Parameter type is neither a pointer nor a reference (by value).
- What is decltype? When do we use it? How its value changes with the use of operator () ? Hint - look at effective modern c++ item 3.
- How you will ensure that the type being deduced is the type you expect? Hint - look at effective modern c++ item 4.
- string literal
- add
C++ 14 -
- Can we deduct return type of a function from auto? What is the syntax difference when we use decltype to detct the type of function's return value between c++11 and c++14? Hint - look at effective modern c++ item 2 and 3.
STL -
- What is the difference between size and capacity in linear containers like vector?
- What is the difference between set and map?
- What is the different between multimap and map?
- What is the difference between map and unordered_map?
- What is associative array? How you will implement it?
- How you will have a function that can handle any stl container and iterate through it?
- How you will delete the value from stl container?
- How you can insert a value in map and be sure that value get inserted ? means there will a possibility there is another value already there, so map will not insert new value with same key ?
- What insert function will return in MAP container.
- Is it possible to have user define key in MAP? Hint - overload > operator.
- Added to previous question, is there any other way, we can achieve user defined key but dont overload > operator?
- How to use pair<T,T> as key in MAP?
- What is the different between list and vector?
- Can we have vector of references?
Multithreading -
- Questions on multitheading concepts -
- What do you understand by mutual execution?
- What is the difference between process and thread?
- How many threads we shall create for our application?
- How many types of thread do we have?
- What do you understand by join and detach?
- How conditional variable works, give some example?
- Can we assign weight to threads? If yes, then how we will do it?
- Difference between Mutex and Semaphore?
- Implement Mutex.
- Implement Semaphore.
- Questions on Multithreading based implementations -
- Producer-consumer-problem: We will have many producer threads and many consumer threads. Like event driven system, as and when any event occur, your producer thread will create event and add them into event buffer (or queue), your consumer threads will act on those event and respond properly. How you will design the system, as your queue will be shared between producer and consumer.
- Read-write-problem: You have common data structure, where many read-write threads access that DS, while updating the data it should not allow reader threads to read it and any number of reader threads can read the data simultaneously.
- Suppose you have hundreds of threads, to serve many client request. Design a thread scheduler, and demonstrate how you are going to handle all resources.
- You have 3 threads, T1, T2 and T3. How you will make-sure that T1 gets executed first, then T3 and then T2? Or how you will implement a sequential execution in multi-threading environment?
- C++ Specific
- What is future and promise?
- What is the difference between std::atomic<bool> type and std::atomic_flag type?
- add