GlobalLogic Interview

 Toplevel traversal in a BST
Class with parent virtual function defined (program)
Virtual destructor
copy constructor, copy constructor why do we give reference
Polymorphism
Frequency of characters in "globallogic"

If we declare a constructor as private, can we create an object ?
Ans: we can't create object on stack but we can create on heap using new 

Even or odd using Thread coding question

#include <thread>
#include <iostream>
using namespace std;

void even_func(int n)
{
    if(n%2 == 0)
    {
        cout << "Number is even" <<endl;
    }
    
}
void odd_func(int n)
{
    if(n%2 != 0)
    {
        cout << "Number is odd" <<endl;
    }
    
}

int main()
{
     for(int i=0; i< 100; i++)
     {
        thread th1(even_func, i);
        thread th2(odd_func, i);
        
        th1.join();
        th2.join();
     }
    

    
}

https://www.toptal.com/c-plus-plus/interview-questions

class Base { virtual void method() {std::cout << "from Base" << std::endl;} public: virtual ~Base() {method();} void baseMethod() {method();} }; class A : public Base { void method() {std::cout << "from A" << std::endl;} public: ~A() {method();} }; int main(void) { Base* base = new A; base->baseMethod(); delete base; return 0; }

https://www.ambitionbox.com/interviews/globallogic-interview-questions


Round 2
------
What is function overloading ? how to distinguish 2 functions
void func(int a)
{}

void func(int a,int b=0)
{}

int main()
{

   func(20);

}
What is template specialization, write a code to do function overloading using template specialization

template <class T>
void fun(T a)
{
   cout << "The main template fun(): "
        << a << endl;
}
 
template<>
void fun(int a)
{
    cout << "Specialized Template for int type: "
         << a << endl;
}
 
int main()
{
    fun<char>('a');
    fun<int>(10);
    fun<float>(10.14);
}


smart pointers , difference between weak_ptr and shared_ptr
SOLID principle

Coding:-
swap bits of a single number , need to know std::bitset or vector<bool> or  bitwise operators

#include <iostream>
#include <bitset>
using namespace std;


void swap_bits(int a,int pos, int pos2)
{
  std::bitset<sizeof(a)> b(a); // array of bool
   cout << b.to_string() <<endl;
  bool temp = b[pos];
  b[pos] = b[pos2];
  b[pos2] = temp;
   
   cout << b.to_ulong() <<endl; 
}
int main()
{
    swap_bits(5,1,2);
    
}


C++11/14 features
Coding:-
Why run time polymorphism is used of it takes time for run-time (SOLID principle)
Why use run time polymorphism? (Reusability) , you can create library of parent class and do runtime linking
Tightly coupled vs weakly coupled(SOLID)
endl vs '\n'
When a complete line of output needs to be flushed, the std::endl manipulator may be used
Stages of compilation /compiler
why namespace is used ?
cin/cout vs scanf/printf difference
Ans:-  
 support type-safe input and output. This means that they automatically handle the conversion of data types, making it easier to read and write data in your C++ programs.

use std::ios::sync_with_stdio(false); for making cin faster than scanf



sync_with_stdio()

Sets whether the standard C++ streams are synchronized to the standard C streams after each input/output operation.

Comments

Popular posts from this blog

Motorola(Dynamic Technologies) Kolkata

Euronet interview questions