Monday 4 January 2016

Interview Questions asked for C/C++, 4-6 years of experience



Interview Questions asked :-





Harman (Formerly Symphony Teleca)
------------------------------------------------
First round:-
---------------
1. Initializer list in C++ and why its used? Advantages ?
2. Object slicing ?
3. Name mangling in c++?
4.STL - vector, syntax and make a copy of a vector?
5. what is iterator?
6. Can we update a value in map if yes then how? and no then why?
7. Difference b/t set and map? what DS they used?
8. In list what DS used and pointer taken is moveable unidirectional or bi-directional?
9.Virtual function how vptr and vtable associated here?
10. Virtual destructor and virtual constructor?
11.Design a game and write a sudo code for game - snake and ladder with condition
ladder:- 9 --> 99
20 --> 50
snake:- 98 -- > 8
51--->2
like this.
---My answer was to use MAP (STL ) in this case and store values in pair for each node .
like (1-1),(2-2) ------(9-99) ...(20-50) ...(51-2) .....(98-8) and at every move , move control cursor to second value of pair.
like if it move to 9, then move cursor to pair.second that is 99.

12. Design pattern? only definitions as i said i dont have exp in this.
13. Debugging a multithread application? If crashed, then how you know in which thread it crashed?
---gdb) info thread
14. switching b/w threads in gdb?
----(gdb) thread <thread no where u want to switch>
15. cronjobs and which demon is running in backend?
---crond
16. About c++ 11?

 Second Round:-
--------------------
(uffff most difficult interview ever faced --- with marker and white board --around 2.5 hours )
1. Design a system if producer is here in India and consumer is in US.
 --- Three way hand shaking?
---whats inside SYN? what is passive open and active open and what does it mean?
---socket calls at server and client end?
---what accept do?
---- can we use bind() at client side , if yes then how if no then why?
Ans:- On the client side, you would only use bind if you want to use a specific client-side port, which is rare. Usually on the client, you specify the IP address and port of the server machine, and the OS will pick which port you will use. Generally you don't care, but in some cases, there may be a firewall on the client that only allows outgoing connections on certain port. In that case, you will need to bind to a specific port before the connection attempt will work.

---- At which socket function call at  server side and client side,three way handshaking happens?
Ans---Its accept() call at server side  (passive open) after this call server ready fying itself to make a connection.
and at client side it connect() call, (active open), in this call client send SYN message and does three way handshaking, connect(), return only when connection being established.


----blocking and non-blocking, how you make it non-blocking?
----multiple clients then? all about select, parameter passed and return type?
----return types of all socket apis at server end?
----socket(), what parameter passed here?
--- At which api this three way handshaking happens?
--- In case of UDP , what is socket api calls at server and client end?
---connect() parameter list and return type?
---what is ipv4 and ipv6, difference, why we need ipv6?, different type of ipv4 (A,B,C,D), how you decide which one to use?
Ans-- ipv4 , 32 address space, containing host address and network address, represented in decimal number
A: 2^31 number of ip address
B : 2^30 number of ip address
C : 2^29 number of ip address
D : 2^28 number of ip address (multicast)
E : 2^27 number of ip address ( reverse for future use)

Ipv6: 128 bit address space, total ip available 2^128, represented in group of 8 hexadecimal number separated by ':'
Ex:3FFE:085B:1F1F:0000:0000:0000:00A9:1234
Ex1: 3FFE:85B:1F1F::A9:1234
:: = all zeros in one or more group of 16-bit hexadecimal numbers



--- how you decide that for a particular process , how much RAM is needed?
--- Paging and virtual memory/
---In you project or work you get fage fault? what is this? and how to avoid page faults?

had a lunch and came back.

2. Design the same system, if there is multiple thread of producer and consumer within same process.
--pthread_t_create() syntax?
--why second sysntax is null for this , pthread_t_attr ?
---third parameter syntax, if more than one parameter need to pass then how to will you manage its last paramter?
---pthread_t , what is this?
--- thread_id, passed in pthread_t_create(), its by value of by reference?
---who create this thread_id ,  you??
---then move to my question, what shared resource we use? I said , its Queue.
---- how queue work internally? structure and how its checks for its empty or full?
----where in memory that shared resource will use  , i.e queue in my case, where its in memory?
--- is Queue is thread safe?
----can we use vector here? at which place we use vector and where we use link list?
--- size of vector? vector.size() and vector.empty(), whats the difference?
----data structure available in C++?
3. C++
---operator overloading u used in your project.
---- overload assignment operator, write a code.
----encapsulations?
----if you have a member function f1 private and other function f2 public , can you access f1 in f2?
---virtual function? how we decide to make a function virtual or not?


Clear-Trail:-
-----------------
1. Tell me about your self in term of your role, project and technology used?
2. Tell me about project in which you feel comfortable?
3.TCP/IP- how data flows at network level.
4. TCP dump? how and when you used?
5. when you pressed www.google.com, then what happened in back end at network level.
6. All about http you know?
7. Virtual constructor and virtual destructor?
8. Many question on virtual memory, like if program needed 30MB of memory but only 15mb space is available on RAM, so is it possible to run the program.
9. Now if available disk space is limited then how OS will manage to launch this program.
10. if we ran 4 instances of same program then?
11. micro in c++ .
12. function pointer?
13. can we achieve functionality by using micro and function and vice-versa.
Ex: #define sum(a,b) (a+b)
or we can write a function : int sum(int a, int b)
so can we use any thing in program to achieve the functionality (forget about performance, size of the binary , loop, recursion and all), if not then in which case we cant use micro?
14. 4 process A,B,C,D is given and they share a shared variable x by semaphore. now when A and B start execution then then they copies value of shared variable x in a temp varialbe , increment value of temp varialbe by 1 and then terminate. Similarly for process C and D, but while execution they decrement shared variable value by 2.
Input : semVal = 3 and x=0,
now tell me max value of x achieved during this . (each process will get executed only by once.)

Second Round with Manager and Tech Lead:-
This interview was about 1+ hours and they ask me only about project and technology used there.
1. Explain your project, your role and module handled by you.
2. If you are doing data communication and one of the client/server has crashed then how you will maintain the data/request lose?
3.You are using DB to save the req, what is the ulternative of DB to use here?
4. I said we can use file or Dfile, then he asked Whats advantages and disadvanges of using file instead of using DB?
5.What shared resource you used in your CRBT project.
-- I said Queue.
6. Implementation of Queue? Mutex?
7. What protocol used between Client and server, wants to know that how server read the packet whats the protocol shared between FE and BE.
--- read packet bit by bit, like first n bit will be request type , next n bit bill be subscriber id and all.
8. Handling of data flow if any server is crashed and client is continiously sending requests.
--like error handling after send() or recv().
9. Blocking and non-blocking calls?
10. If I am a client and want to check every thing is working as expected on live server , then how i will check?
---I said by checking logs.
Asked no , dont have access to logs..
---I said we monitor the TPS by netstat on port, if chocking then we need to increase no of worker thread count. and monitor connection between then.
---- by tcp dump we can check how data is flowing b/t client and server.
---- We can configure some monitoring script , you can check from there also.
11. Questions on multi-thread, if many arguments to pass to function then?
---use structure and send structure as argument to function.

Many times he motivated me let me feel comfortable.

HR Round:-
Salary negotiation.

-------------------------------------------------------------------------------------------------------------------------

Ciena:-
---------
First round:-
1. TCP/ IP connections stages (established , closed, FIN_WAIT, FIN......)?
Ans----Connection Tear-down (modified three way handshake).

        The client sends a FIN (active close). This is a now a half-closed connection. The client no longer sends data, but is still able to receive data from the server. Upon receiving this FIN, the server enters a passive close state.
        The server sends an ACK (which is the clients FIN sequence + 1)
        The server sends its own FIN.
        The client sends an ACK (which is server's FIN sequence + 1). Upon receiving this ACK, the server closes the connection.

A half-closed connection can be used to terminate sending data while sill receiving data. Socket applications can call shutdown with the second argument set to 1 to enter this state.

SYN_SEND Indicates active open.

SYN_RECEIVED Server just received SYN from the client.

ESTABLISHED Client received server's SYN and session is established.

LISTEN Server is ready to accept connection.

NOTE: See documentation for listen() socket call. TCP sockets in listening state are not shown - this is a limitation of NETSTAT. For additional information, please see the following article in the Microsoft Knowledge Base:
134404 NETSTAT.EXE Does Not Show TCP Listen Sockets

FIN_WAIT_1 Indicates active close.

TIMED_WAIT Client enters this state after active close.

CLOSE_WAIT Indicates passive close. Server just received first FIN from a client.

FIN_WAIT_2 Client just received acknowledgment of its first FIN from the server.

LAST_ACK Server is in this state when it sends its own FIN.

CLOSED Server received ACK from client and connection is closed.
As an example, consider the following scenario:

A socket application has been terminated, but Netstat reports the socket in a CLOSE_WAIT state. This could indicate that the client properly closed the connection (FIN has been sent), but the server still has its socket open. This could be the result of one instance (among all threads or processes) of the socket not being closed.

NOTE: It is normal to have a socket in the TIME_WAIT state for a long period of time. The time is specified in RFC793 as twice the Maximum Segment Lifetime (MSL). MSL is specified to be 2 minutes. So, a socket could be in a TIME_WAIT state for as long as 4 minutes. Some systems implement different values (less than 2 minutes) for the MSL. 

2. TCP dump, describe and where you used?
3. if TCP connection stage is FIN_WAIT, how will you debug this, means whats the problem behind this?
4. Public, protected and private? differences?
5. Copy constructor? and why we need to write your own?
6. socket system calls?
7. use of bind system call? can we call it at client side? if get called the what will be the behavior?
8. Array - int is given, and you need to find pair of numbers having given sum.
9. Write a program to find if a machine is big endian or little endian?
10. Write a program to find whether a number is even or odd using bitwise?
11. Asked me about casting, types and explanation where you can use?

Second Round:-
1. what is array and linked list in terms of memory created?
2. why memory created in linked list are not contiguous?
3. int arr[400] and int *arr[400] what is the difference between these two, in term of memory representation?
4. how to store data in *arr[400] and access the same?
5. semaphore and mutex differences? live examples?
6. WAP of procedure consumer problem, while reading and writing a data in/from a shared queue?
7. Doubly linked list , add node at a given position?
8. Puzzle a square is given, with dimension 3 unit each, if we  put 2 cuts on each faces then how much maximum square will be produced?
Ans--my answer was 0. 

--------------------------------------------------------------------------------------------------------------
Safenet (again)
------------------------- 
First Round:-
  1. System calls in socket programing.
  2. which call is blocked and which is non-block.
  3. how to avoid blocking of the calls?
  4. use of select and fnctl function.
  5. if client of server has crashed or non responsive , how will u handle this or how will u come to know the same.
  6. More IPC techniques you worked with?
  7. GDB, debugging core files?
  8. debugging memory leaks? any tools used?
  9. describe a project you feel comfortable with?
  10. Write a program to reverse a link list.
  11. Create dynamic 2D array.
  12. makefile?
  13.  

Second Round:-
1. Tell me about the project you worked on.
2. name mangling and "extern C" in C++.
3. header guard in C?
4. processioning in C?, ifdef and endif?
5.static, volatile and global variable?
6. Unsorted int array is given, write a program to find largest subsequent array numbers with max sum.
ex: array: 3 9 7 4 8 2 1 10
o/p: 4 8


-----------------------------------------------------------------------------------------------------------

FIS Global
----------------
Written:-
    C and C++ both, online
    cleared.

Technical round:-
  1. class A {
            int a;
            int b;
            public:   
                void show()
                { }
        };
    class B : public A
    {
        int c;
        public:
            void display () {}
    };

    int main()
    {
        A a;
        B b;
        cout <<sizeof(a) <<sizeof(b);
    }
    Ans: 8 12

2)  Use of recursion ? slow or fast with reason?
    --- use of recursion makes the program perform slower and consumes more memory than use of iterative methods. Because internally its use stack for backtracking, that consumes more memory and stack management makes program to perform slower.

3) char * p;
    p[0] = ‘c’;
    printf(“%c”,p[0]);
output?
Ans:-- it will give segmentation fault. because pointer p does not have memory created.
to make it works, we need to create memory for this.

p = malloc(sizeof(char)); // memory for only one byte created.

4) what malloc return? do you not think some is missed in above malloc statement?
----malloc returns void *. so we need to type caste it on corresponding data type. but in C, compiler automatically convert it in corresponding data type, but in C++, we need to do it by our self.

5) create a structure, take its pointer and assign values to its variable, one variable must me of char *.
---Ans:--
struct
{
    int a;
    char *p;
} s;
int main()
{
    struct s *temp=NULL;
    temp = (struct s*) malloc (sizeof(struct a));
    temp -> p = (char*) malloc (sizeof(char) * 10) // suppose want to copy a string of len 10;

    temp -> a = 10;
    strcpy (temp->p, “hello world”);
}

6) In the above can we do temp->p = “abcd”?
can we modify above string “abcd” to “abdd”, by using temp->p[2] =’d’;

--Ans--- Yes we can point p to “abcd”, but we cant modify that string. because p is only a pointer and here its pointing to base address of string “abcd”.

7) How to debug core file
--Ans:- file corefile ---it will give the name of process which has created that core file.
now start gdb.
gdb <process name> < core file name>
    < now it will stop where its got crashed>
now use by using ‘bt’ command we can see the backtrace of function call.
now by using ‘bt -full’ we can see the exact values which are passing to this function.

8) in gdb when you fire ‘bt’ command you see numbers on left side from 1 2 3 ….. what is that?
    Ans--- bt command actually shows the backtrace of function called. So its shows the stack indexes of function call.

9) In the above question , if i ask you to step into function at stack index 2, then how you will do?

10) multithread application: if you don't use synchronization method in while writing to a file, if there is two thread are running and both are using same file descriptor, then what's the problem?

---Ans: my answer was there be not be any problem, both will write to same file, but order of writing will be random. < Need to check on net whether both thread can share same file descriptor or not, and most probably yes they share, source of thinking is “procedure and consumer problem” >

11) if you have developed a program , it's working fine today on customer site, but after one month its not working properly, it's slow in response, response is not correct, some time its crashes.  you are new to the company, you don't know more about the code, what will be your approach to debug it.

---Ans:- My answer was, if a program is working today and and getting crashes after 1 months or two, it means there is a problem of memory leak in program. if there is a log maintained,  I will check number of time dynamic memory gets created and number of time dynamic memory is getting released, it should be equal.

If it's slow, then probably will check, queue maintained by program, whether it's able to handle load of incoming requests or not. It not, then probably we need to start more threads.

If program is connected to database, so need to check response time from data base for particular query, if data stored is more on tables, and if proper indexing is not done on table, then probably it could be one of the important reason.

11) grep command to search for more than one pattern.
    grep -e “hello” “ram” <file>
12) Blocking or non blocking call? when read() and write() call blocked. what to use to make it non-blocking?
--Ans-- read() or write() calls blocked when there is nothing in buffer to read or buffer is full , there is no space to write.
to make it non-block we use select() system call.

13) How timeout functionality works in socket? if server is not responding how it shows time out occurred?

14) what is extern?
    extern int i; what does in mean?
-- this is the declaration of i, means no memory is getting created for that i;
extern int i = 10; what does it mean?
--this is definition + initialization of a variable i;


Second Round:-
It was manegerial round, they told me about the project they are handling and what will be my role, its was for the maintainence project and my role was bug fixing and writing unit test cases only and project is not a long term project.

I denied to accept the offer.

-----------------------------------------------------------------------------------------------------
U2opia mobile's:-  
---------------------------- 
Written:-
    C/C++/OS/Networking/data structure 10 questions of each.
    cleared.

Technical round:-
  1. set 4th bit of char to 1.
    Ans:- int bitset(int num,int bitNo)
    {
     num = num | (1 << bitNo);
    }
  2. big endian and little endian? if you say it understand lower or higher bit first, what does it mean? what compiler do internally, to distinguish between these two type.

#include <stdio.h>
int main()
{
   unsigned int i = 1;
   char *c = (char*)&i;
   if (*c)   
       printf("Little endian");
   else
       printf("Big endian");
   getchar();
   return 0;
}

or

#include <stdio.h>
int main ()
{
  unsigned int x = 0x76543210;
  char *c = (char*) &x;

  printf ("*c is: 0x%x\n", *c);
  if (*c == 0x10)
  {
    printf ("Underlying architecture is little endian. \n");
  }
  else
  {
     printf ("Underlying architecture is big endian. \n");
  }

  return 0;
}
  1. what is decision factor to make a program multiprocessor and multithreaded?
  2. In socket what is blocking and non-blocking call?
  3. what is select(), parameter of select(). Are you sure to make call blocking to non-blocking, this make is useful? nmake().
  4. what if we use NULL and 0 as parameter of timeout in make function.
  5. difference between constant pointer and pointer to a constant?
  6. message passing IPC?, when  and how you decide to use which IPC technique and why?

-----------------------------------------------------------------------------------------------------
HCL:-
----------
  1. char *p;
strcpy(p,”hello”);
will it work?
      2)  core file? how you debug it using gdb?
    --Ans: gdb <processname> <core file>
        bt
        bt -full
      3) if program is crashes on customer site, then what does it mean, and how you debug it, if
    you dont have core file or core file generation is disabled on that machine.
    ---Ans:-- First we will try to reproduce the issue on local machine using some random input, if its getting reproduced, then ok, we can proceed it with debuging.
if not able to reproduce it, try to find out the input which cause crashing, will try to generate same data on our local machine, if succeed , then its ok if not then we need to import that data on our local machine to reproduce this.
start debugging, with input and it will get crashed, at the point of crash we can fire bt or bt -full command to find out the exact function and line where its getting crashed.

      4) implement own memmove(), how you handle overlapping in memory.
      5) difference between memmove and memcpy().
      6) mutex and synchronization? procedure and consumer problem?
    ---Ans:-
      7) pthread_cond_wait() and pthread_wait_signal() ?
    Ans:- ptherea_cond_wait() --- this function is get called when a thread is waiting for particular condition  i.e particular resource to be available., if that particular resource is available another thread will call pthread_wait_signal(), to notify first thread that the resource is available now for what it was in waiting condition.
   
      8) extern and static keyword?
      9) a.c
    static int a;
    int main()
    {
        fun()
    }
    fun ()
    { a++; }
   
    //b.c
    int main()
{ fun1();}
fun1()
{
    printf(“%d”,a);
}

will it compile?
---Ans: no it will not compile , it will a is undeclared.
because a is declared in a.c as a static and its scope is till file a.c
if we want it to work , we need to delcare variable a in b.c as well.

10) how will you compile these two files.
--Ans:- cc a.c b.c
11) how to compile these file using makefile?
----Ans: in makefile
ABC : a.o b.o
    gcc ABC a.o b.o
a.o : a.c
    gcc -o a.c
b.o : b.c
    gcc -o b.c

12) A rope is given , if burn it from any of the end, it take 1 hr to completely burn, calculate half an hour.

13) three balls, one ball is lighter, find lighter one in minimum comparison.

14) three bulb three switch puzzle.
    
-------------------------------------------------------------------------------------------------------------------

Xavient:-
--------------

Technical round:-
  1. Tell me about current project.
  2. tell me about your previous project. whole structure and all intermediate modules and connection among them.
  3. Describe end to end flow of project, how request comes and which protocols you used.
  4. How you used socket with TCP, how to you validate that received packet at server end is valid? and you read data from packet?
  5. which technology you used in socket, polling or pushing?
  6. what you do for query optimization?
  7. how to integrate with oracle with your C code?
  8. makefile?
  9. if there is a million of data on your database, how you deal with such a huge data while selecting or update on that?
  10. Thread safe? how to make a threads safe?
  11. mutex and semaphores difference? which one i used?
  12. Difference between python and C++ in term of usage (high level)
  13. basics of shell script
   
   
Second technical round:-
  1. Technical background, what projects and technologies used?
  2. Have you done any project from scratch? what was your role? were u involved in designing if yes then how much, or what point you have added?
  3. if you have to design a project , how will you start explain step by step?
  4. Have you used any tool while designing high level or low level?
  5. How you reuse code in your new project in C and in C++.
  6. I told in C++, we can use inheritance, but next he asked ok agree, but why people derived from base class , why not he just go to base class and add additional functionality for new project or product? Hint:- what problem comes while testing?
  7. virtual function, vtable and vptr, how run time polymorphism happens using vtable and vptr? what compiler do to achieve runtime polymorphism?
  8. pure virtual function and abstract class? why we can’t create its instance, who prevent compiler to create its object?
  9. all type of casting? static caste, write case where you use static_cast. and what is the difference between static and reinterpret caste?
  10. what is socket? socket id? if you create a socket then what happen at kernel level, where in kernel it stores socket id and other socket related info?
  11. Every thing in linux is file, so what is inode? now tell me what is socket id, is it inode, if yes then what is socket, is it a file? if yes then can we perform read write operation rather than send recv()?
  12. socket server all system calls?
  13. byte ordering? little indian and big indian?
  14. what is difference between htns() and htnl(), why we use it?
  15. how data transfer between two system , do not tell layerwise, actually tell me when your data reaches to physical layer then how it reaches to other system? hint:- by electrical cable by using set or unset bit?
  16. fork() system call ? after calling this fork(), we want some part of code is to execute by child process only , how will do that? or if any line is executed, tell me how to know by which process (child or parent) that line gets executed?
  17. how to know how many process is running on your linux machine.
  18. how to know process id of init()?
  19. how to print last 10 line of file in linux?
  20. difference between cut and awk?
  21. what grep do? and what is pipe? have you used pipe as a interprocess communication in your project?
  22. where all shell command are stored in linux file system?
  23. if some user is firing and command let say ls, is system is giving “command not found”, then what is the reason?
  24. where directory bin resides in linux file system?
  25. file structure of /etc directory?
  26. which algo used in linux to encrypt password?
  27. what is rpm and appget ? and when you write appget rpm ------ then what happened at kernel level? there must be master data base from where kernel fetches information regarding package you are going to install, so tell me location?
  28. svn usage by command line.
  29. makefile? how to add macro in makefile? install target in makefile? what it does?
  30. makefile - add target?
  31. crontab, how to schedule a job inside that?
  32. .bash_profile file, what it contains? if you create a aliase inside that by a user1, and save the file , and then he type that aliase but thats not working?  why ?
  33. Now aliases is working for user1 after log in again , but not woking for user2, why?
  34. XML parsing? how will you do ?

HR round:-
  1. Salary negotiation.
  2. Reason of leaving?
-----------------------------------------------------------------------------------------------------------

Safenet/Gemalto:-
--------------------------

First round:-
  1. which all data structure you used?
  2. implement a queue using link list? structure declaration for queue.
  3. insert an element in queue.
  4. delete an element in queue.
  5. link list given you have to delete alternate node.
  6. suppose structure of list is as below
   
struct node{
        int id;   
        char *p
        struct node *next
        }
where id denotes the index after.
so insert this type of node after 3rd node in existing list.

7) delete a node of linked list having a node structure given above.
8) 2D array dynamic creation using double pointer?
9) detect a loop in a link list?
10) about project structure?

Manager round:-
  1. TCP 3-way handshaking in details.
  2. UDP usage? how socket knows whether connection is for TCP or UDP?
  3. int *(arr[])(), what it’s signify?, if its a function then what its returning and what's parameter is passing.
  4. socket -- using polling or pushing in your project?
  5. grep and sed commands, replace string of lowercase  with uppercase  using sed.
  6. which database i used?
  7. difference between group by and order by?
  8. select id,name from table order by id, will it work or not?
  9. how data communication is happening in my project, who we are receiving data at server end how  to read it?
  10. A number is odd or even by using bitwise operator.

Director round:-
  1. Tell me all about any of one project i am comfortable with?
  2. all different component and protocols used among them?
  3. Which database and how it's integrated with my C or C++ code?
  4. How you are reading tcp packets?
  5. what is byte ordering?
  6. socket polling or pushing?
  7. which type of work i am looking for in safenet?
  8. multithreading ? how we make any application a multithreaded? what all threads shared?
  9. How you make in your project a multithreaded, explain by drawing a project structure?
  10. About my family , their educational background and occupations?
  11. Any question , and said Good luck.

HR said you are on hold, did not get call after that.

-------------------------------------------------------------------------------------------

NIIT Tech:-
-----------------
1) GDB, find where value of a variable changed?
2) how to set break point based on any condition?
3) how to compile code in debug mode?
4) how to link library in your code at compile time.
5) how to create a process and how to check whether running process is parent or child?
6) shallow copy and deep copy?
7) pure virtual funciton? if we defined pure virtual funciton in base command then code will compile or not?
8) static binding and dynamic binding?
9) object slicing?
10) A file is given how to check whether it is a simple file or script.
11) how to find a list of files modified a day before in a directory.
12) how to check a file exist or not in a directory.
13) grep command to exclude a pattern.

-------------------------------------------------------------------------------------
WOW vision:-
--------------------
1) TCP/IP three way handshaking will all calls? this three way handshaking happen while making connection or while data transfer.
2) UDP why its used?, and how sender know that data has been received at other end?
3) semaphore and mutex?, binary semaphore and mutex are same, if not then what is the difference?
4) In multithreading application what u used mutex or semaphore?
5) is process shared critical section , what is critical section?
6) a program is given (a.exe), how to make this program so that only one instance run at time.Means if program a is already running then we can not run this program again. you u try it will say “program a is already running”.
7)Design algo for LIFT (elevator) which data structure will u use?
8) socket program all system calls get called at server side and client side.

Second Round:-
1) About static keyword in C?
2) socket calls for TCP and UDP?
3) multithreading, pthread.
4) semaphore and mutex? diff?
5) link list is given having alphabets, delete the node containing alphabet ‘e’.
6) delete a node in link list if only access to that is given.
7) string is given like AAAABBBCCAAERRRBBNNNN output should be A3B3C2A2E1R3B2N4.
8) write a multithreaded application where one thread is writing in buffer and other thread is reading from that buffer.
9) copy constructor?
10) virtual function?

-----------------------------------------------------------------------------------------------------
Symphony Teleca:-
----------------------------------
1) int *a where memory of *a is stored? in stack , heap or anywhere else?
-- Answers : it's like a local variable, its memory 4 byte is stored in stack.
*a = malloc (); then also memory for *a stored in stack and its pointing to another memory location which is in heap.

2) if a variable is declare as int a in .h file. If you include this header file in two of source file suppose in x.c or y.c then will it compile?
-- Answers: No it will send multiple declaration of a variable a. So to resolve this we have to declare it as 'extern int a ' in header file.

3)GSM architecture?

4) suppose in OS int size if 1 byte.
   for (i=0;i<1000;i++)
      printf("%d",i);
     
   what will be the output?
   
   ---Answers: its output will be 0 to 255 then again 0 to 255 and so on till infinity.

5) Implement queue using two stacks?

6) stack operation : push pop and maintain max element on each pop or push. How to implement it?
--Answers : Using two stack. 1 for pushing and popping elements and other is for maintaining max element present in stack.
algo: just push element in stack1. and compare that element with top element of stack2. If that element is greater than top element of stack2, then push that element to second stack2 and it will be the max element.
now if you are popping element is the top element of stack2 then pop it from stack2 as well , so now top element in stack2 will be the top element.

7) pthread_create arguments?
--Answers : pthread_create(pthread_t,pthread_attr,(void *) functionName, (void*) argument);
here only one argument is passing , so if the function required multiple arguments then pass structure or array as a argument here.

8) Semaphore and mutex ?

9) Difference between binary semaphore and mutex?
--Answers :He said yes there is some difference, i Told they are very similar only difference is they use signaling and locking mechanism respectively only.

-----------------------------------------------------------------------------------------------------------------------
APTportfolio:-
---------------------
  1. Mutex? and semaphore?
  2. virtual function ? Why we do not declare every function as virtual in base class, might be in future we need function definition with same name in derived class?
    -Answers :- Yes we can do, in java every function in base class is virtual.

  1. Pure virtual function ? and why it's used?
  2. abstract class, if we can't create object of it, then whats is use?
---Answers:- when we want to make a class a common class or interface then we use abstract class.
So which function we have to make a common function we declare that function as pure virtual function in base class. and define then in derived class accordingly.

  1. system call(), when you call a system call what happens internally in your program? comparison when you call used defined function and a system call?
--Answers: Memory layout - kernel space and user space (stack,heap,data segments,text    code). So when we call a system call , then control packed all arguments required for system call and then control moves to the kernel space where system calls are defined.
Perform action and then control switches to user memory space.
But a user defined function resides in user memory space only.

  1. Deadlock, its reason and methods to avoid it?
--Answer : Deadlock is a situation when two or more processes wait for each other to finish and none of them ever finish.
Reasons:
Mutual Exclusion: There is resource that cannot be shared.
Hold and Wait: A process is holding at least one resource and waiting for another resource which is with some other process.
No Preemption: The operating system is not allowed to take a resource back from a process until process gives it back.
Circular Wait:  A set of processes are waiting for each other in circular form.


  1. virtual memory?
    --Answers:- Virtual memory or logical memory is an additional memory that can be used
same as  physical memory for better OS performance.
Suppose OS is running some of the process, OS want to run more processes but for them required physical memory is not there, so OS will virtual memory in that case, it will use virtual memory to load process or program.

  1. 32 bit and 64 bit machine difference?

    32 bit and 64 bit machine difference?
Here's the simplified technical side to it.
32-bit (also known as x86) and 64-bit (also known as x64) designate the width of the CPU register. The CPU register is a small amount of storage on the CPU, which the CPU uses to keep the data it needs for optimum performance. Today's CPU's are commonly 64-bit units that are backwards compatible with 32-bit.

32-bit operating systems only make use of 32-bits of space on the CPU, and are only able to handle 2^32 addresses or 4,294,967,296 bits [1 byte = 8 bits, 1kb = 1024 bytes, 1mb = 1024kb, 1gb = 1024mb so 4Gb is actually 4,295,000,000 bits.] thus the 4GB of RAM limitation (Only 3.25GB will be usable.)

64-bit operating systems make use of all 64-bits of space on the CPU, and are able to handle 2^64 addresses or 64-bit is 2^64 = 1.8446744e+19 bits, which is virtually unlimited RAM (at today's standards)

As the number of bits increases there are two important benefits.

  • More bits means that data can be processed in larger chunks which also means more accurately.
  • More bits means our system can point to or address a larger number of locations in physical memory.

Relate it with physical (RAM) and virtual memory. OS load programs in physical memory to run. in case of shortage of physical memory (RAM) OS uses virtual memory to load the program. so 32 bit operating system can support max RAM of 4 GB, means only 4 GB memory is available to OS to run the programs, beyond that it will use virtual memory (which is also limited to that OS).
But in case of 64 bit operating system it supports unlimited RAM, so it can handle or run more programs without memory violation.


    Processor, OS and application hierarchy


To run a 64-bit operating system you need support from the lower level: the 64-bit CPU.
To run a 64-bit application you need support from all lower levels: the 64-bit OS and the 64-bit CPU.
This simplification will be enough for us to look what happens when we mix the 32-bit and 64-bit parts. But if you want to understand the issue more deeply then you will also need to consider the hardware that supports the CPU and the device drivers that allow the OS and the applications to interface with the system hardware.

    The general rule is that 32-bit will run on a lower level 64-bit component but 64-bit does not run on a lower level 32-bit component:
  • A 32-bit OS will run on a 32-bit or 64-bit processor without any problem.
  • A 32-bit application will run on a 32-bit or 64-bit OS without any problem.
  • But a 64-bit application will only run on a 64-bit OS and a 64-bit OS will only run on a 64-bit processor.


  1. inline function(), where it's used? and is it always faster?
    ---Answer:- When program execute the function call, CPU stores the memory address of
    function instruction, stores function argument in stack, and finally transfer control to the
    specified function. CPU then execute the function code, stores return value in specified
    memory location or register and returns the control back to the calling function.
    So two things happen, first time in switching between functions and time taken in
    execution of function body.
    some time time taken in switching is more than time taken in execution of function
    body. So in that case CPU wastes maximum time in switching. So in these cases we
    use inline function, this expands the code in function body at the place where it get
called.

inlining is only a request to the compiler, not a command. Compiler can ignore the
request for inlining. Compiler may not perform inlining in such circumstances like:
1) If a function contains a loop. (for, while, do-while)
2) If a function contains static variables.
3) If a function is recursive.
4) If a function return type is other than void, and the return statement doesn’t exist in
function body.
5) If a function contains switch or goto statement.

Inline functions provide following advantages:
1) Function call overhead doesn’t occur.
2) It also saves the overhead of push/pop variables on the stack when function is called.
3) It also saves overhead of a return call from a function.
4) When you inline a function, you may enable compiler to perform context specific
optimization on the body of function. Such optimizations are not possible for normal
function calls. Other optimizations can be obtained by considering the flows of calling
context and the called context.
5) Inline function may be useful (if it is small) for embedded systems because inline can
yield less code than the function call preamble and return.

Inline function disadvantages:
1) The added variables from the inlined function consumes additional registers, After
in-lining function if variables number which are going to use register increases than they
may create overhead on register variable resource utilization. This means that when
inline function body is substituted at the point of function call, total number of variables
used by the function also gets inserted. So the number of register going to be used for
the variables will also get increased. So if after function inlining variable numbers
increase drastically then it would surely cause an overhead on register utilization.

2) If you use too many inline functions then the size of the binary executable file will be
large, because of the duplication of same code.

3) Too much inlining can also reduce your instruction cache hit rate, thus reducing the
speed of instruction fetch from that of cache memory to that of primary memory.

4) Inline function may increase compile time overhead if someone changes the code
inside the inline function then all the calling location has to be recompiled because
compiler would require to replace all the code once again to reflect the changes,
otherwise it will continue with old functionality.

5) Inline functions may not be useful for many embedded systems. Because in
embedded systems code size is more important than speed.

6) Inline functions might cause thrashing because inlining might increase size of the
binary executable file. Thrashing in memory causes performance of computer to
degrade.

-------------------------------------------------------------------------------------------------------------------
Webnet solutions:-
----------------------------
  1. GDB, how to use it, core dump analysis? which signal it sends when segmentation fault occurs?
  2. process and threads difference? in terms of what they share among them and what not?
  3. semaphore and mutex , binary semaphore? which one is better?
  4. pagefault and paging? virtual memory?
  5. when multiple process, then how OS handles them. means he is trying to ask me about process table managed by OS.
  6. int **a, declare a 2D dynamic array.
  7. two link list crossing each other and forming a shape of Y, both are of different length, how to find intersection point?
  8. bit wise operations? add two numbers.

---------------------------------------------------------------------------------------------------------------------

Hughes Systique:-

------------------------------

  1. If you want to declare only one object of the class, then what you will do?
  2. virtual function, vptr and vtable?
  3. virtual destructor? virtual constructor? why C++ doesn't support virtual constructor?
--Answer: Because the vtable that helps provide the polymorphism isn't created/accessible till after the constructor is done constructing the object. For the same reason, you must never call virtual functions inside a constructor. Well, you may call but don't    expect polymorphism.

  1. memory layout of a program.
  2. static  linking of library, dynamic linking of library, which one is better to use?
    --Answer:
  1. how to create a library if source file the given to you.
  2. makefile?
  3. exception handling, write your own exception?
  4. type of exception handling you worked on?
  5. RTTI, static and dynamic type casting? which one is preffer to use in which condition?
  6. socket programing, if server and client is connected, some how server shut down, how client will know that server is shut down?
  7. shallow copy and deep copy?
  8. when you write your own copy constructor?
  9. why copy constructor argument is const? and why it's passed by reference not by pointer?



-----------------------------------------------------------------------------------------------
Pine labs:-
---------------
  1. volatile keyword?
  2. extern keyword?
  3. what is dll, can we edit this file? if yes how?
  4. how dll works, means compiling and linking with your source code.
  5. 2-D dynamic memory creation?
  6. find maximum multiplication of 3 numbers from an array of non zero integers a) when all are positive and b) when there are some negative numbers as well?
  7. memory layout of c program, where environment variable get stored?
  8. threads: what they shared among threads and what not?
  9. memory leak?
  10. avoid memory leak, how free knows the size of memory to delete?
  11. IPC techniques?
  12. Binary semaphore? mutexes and how to use them?
  13. string is given, how to know whether its anagram will form a palindrome or not?
  14. Binary search ?
  15. quick search code
  16. char * ptr = &a ; if a is an integer?
  17. pointer and references ?
  18. constructor? and virtual function?
  19. copy constructor syntax and why it's passed argument is as a reference why not by pointer or value.
  20. what are the things that C++ compiler provides by default?
  21. when we write our own copy constructor?
  22. shallow copy and deep copy?
  23. what scanf and printf returns?
  24. f (     ) printf("hello"); else printf("world"); what to put in if condition to print hello world.
  25. extern keyword?
  26. static keyword? if a static variable is declared in header file, how you can use it in your .c file, as its scope is till a file where it's declared only?
  27. Socket programing :- how to client know that server is connected or not?
  28. what does socket server do to decline any of the client?


2 comments: