-------------------HCL------------------
1. Storage class (register 16bit, 32bit, 64bit)-- depend on register we can allocated, if register is not availabe then it act as auto.
2. Memory layout
3. program of pre increment and postincrement
4. program--> Pllindorme ( number and stirng)
5. Types of environment variable in linux.
6. Relative path and Absolute path.
7. Copy constructor
class A {
A(A & B){} /how
A(A nn){} // what is difference
};
8. STL is static polymorphism ( correct)
9. For string if we pass it will as it is or we have to do some thing.
----------------------------------------------------
1. how to prevent the class from inheretance.
Ans:=-- By creating the singltion class, by making the constructor and distructor as private.
2. virtual distructor/constructer.
Ans-- virtual distructor is possible, but virtual constructor is not possible ( compile time error)
3. function pointer
Ans-- int (*pt2Function)(float, char, char) = NULL; // C
int (TMyClass::*pt2Member)(float, char, char) = NULL; // C++
int (TMyClass::*pt2ConstMember)(float, char, char) const = NULL; // C++
4. int constant pointer and constant integer constant pointer .
Ans-->
int constant pointer--- >>> int *const p;
constant int constant pointer--> const int *const p;
4.difference between the class and strucure ( is structure follow the oops concept).
Ans--
1.by default data member of class is private, and for strructure is public.
2. When we inherit the class to another class it is by default is private, but for structure-- when we inherit class in structure then by default it is pubilc.
5. stack coding - got it
6.class a; cout << sizeof (a).
Ans--- 1 because it will give minimum nonzero to it. so minimum nonzero is 1.
7. static virtual function.
Ans-- we can't declare both static and virtual function at a time.
8. Multiple inheritance y in c++ not in others.
9. how to initilize arrary of object 10. With same value.
Ans-- if we are making object of class then we initilize by using constructor.
but for int a[10] ---- for that still searching.
ANs----- std::vector a(10, Fred(5,7)); the 10 Fred objects in std::vector a will be initialized with Fred(5,7)
10. type of inherientance in C++.
Ans--> single, multiple, multi level, hybrid, hierarchical
11. class a;
{
}
main ()
{
a aa =new a();
free (a);
}QQQ-- what it will give error in compile time or run time, for that we have to include the stdlib.h
-- then it will work fine.
Ans----- free is not declared in this scope.
12. copy constructur working and usages.
Ans-- it is present by default.
construcotr (©)---- class a1 = a2;
13. why we use virtual distructor.
Ans-- when we are making object of base class of child class type, and if we delete base object, then it will not delete the child class distructor, so we are making the virtual distructor, then it will call the child distructor.
14. what is STL. ( Standard Templet library
Sequences
•
C++ Vectors
•
C++ Lists
•
C++ Double-Ended Queues
•
Container Adapters
•
C++ Stacks
•
C++ Queues
•
C++ Priority Queues
•
Associative Containers
•
C++ Bitsets
•
C++ Maps
•
C++ Multimaps
•
C++ Sets
•
C++ Multisets
)
15. what default will created when we create only class??
Ans--> copy constructor,default constructor, distructor, assignment operator, address operator
16. how to delete array object at one shot. like questin 9. ( int* a= new int [10]; for deletion we will use (delete []a;) )
17. deep copy and shallow copy and when we use deep and when we use shallow.
Ans: deep copy : it create a local copy or and do operation, it will not refelect to the original one, performance is slow.
shallow copy: it refer to the data, its performance is better than the deep copy, if the data size is large, instead of copy the large data, we can pass the reference of data.
18. which operator we can not overload.
Ans:-- the operator which we can't overload
.(member access or dot operatior), ?: ( ternary or conditional operator), :: ( scope resoloution operator), .*(pointer to member operatior), sizeof,typeid
19. Dagling pointer: is a pointer pointing to something that has been deallocated using delete.
20. Learn Design Pattern.
1. Singlton .
21. Late binding ( It is used by using the keyword virtual)- Run time it will decide which function will call .
--------------------------- asked in shell script---
Questions Asked in the interviews::
1. Automation of the jobs--- (crontab)
2. how to debug the shell script (set -x)
3. If we remove the Header of the script then also script will run ( script will also run)
4. How to check the how many socket descriptor are opened (netstat) (lsof)
=================================================================================================================================
1. What is Embedded System.
Ans-- it is computer system which will do dedicated function within a larger machenical and electrical system
2. Types of scheduling.
Ans-- ( Long Term Scheduler, Short Term scheduler, Medium Term Schedler)
3. What is ARM
Ans-- ARM is family of instruction set archeticture for computer process based on RISC(reduce instruction set computing)
4. What is Toolchain.
Ans--
The GNU toolchain is a blanket term for a collection of programming tools produced by the GNU Project. These tools form a toolchain (suite of tools used in a serial manner) used for developing applications and operating systems.
5. declaration of array dynamic ( c and c++) and delete it.
Ans--
IN C lang
int i[size];
int *ii = (int *) malloc (size *sizeof(int) );
IN C++ lang
int i[size];
int *ii =new int[size];
6. What is sizeof.
7. how to compile toolchain.
8. IPC mechanism and types of IPC.
Ans-- Socket programming, shared memory
9. Class follow Abstraction of OOPS concept.
10. How the process are Synchronizating.
Ans-- By using the semaphore variable and Mutex varible.
11. Use of constructor??
Ans---
When you instantiate an object it's constructor will be invoked whereas calling a method is always optional. You therefore might forget to call your initialization method and fail to initialize everything correctly.
12. What is split tool, what it will give. ( it is static analysis tool)
13. Can we increment or decrement a void pointer?
Ans-- No
14. Friend functions have the following properties:
1) Friend of the class can be member of some other class.
2) Friend of one class can be friend of another class or all the classes in one program, such a friend is known as GLOBAL FRIEND.
3) Friend can access the private or protected members of the class in which they are declared to be friend, but they can use the members for a specific object.
4) Friends are non-members hence do not get “this” pointer.
5) Friends, can be friend of more than one class, hence they can be used for message passing between the classes.
6) Friend can be declared anywhere (in public, protected or private section) in the class.
15. Friend class is also possible.
16. RTTI( Run time type information)
untime Type Information (RTTI) is the concept of determining the type of any variable during execution (runtime.) The RTTI mechanism contains:
The operator dynamic_cast
The operator typeid
The struct type_info
17. Types of Ploymorphism:
a) Run Time ( dynamic binding)
b) compile tiem ( static binding)
18. Data encapsulation led to the important OOP concept of data hiding.
19. data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details from the user
20. char *s = "Hello world";
will place Hello world in the read-only parts of the memory and making s a pointer to that, making any writing operation on this memory illegal. While doing:
char s[] = "Hello world";
puts the literal string in read-only memory and copies the string to newly allocated memory on the stack. Making
s[0] = 'J'; ( legal)
21.
When the processor wakes up after power on, it goes to a particular memory location. What is that memory location called? ??
Ans-processor goes to MBR (master boot record) then it takes the address of boot loader form thr and execute this boot loader program
22.
Differentiate between a template class and class template.
Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates. Class template: A class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It’s jargon for plain classes.
23.
What are proxy objects?
Objects that stand for other objects are called proxy objects or surrogates.
template <class t="">
class Array2D
{
public:
class Array1D
{
public:
T& operator[] (int index);
const T& operator[] (int index)const;
};
Array1D operator[] (int index);
const Array1D operator[] (int index) const;
};
The following then becomes legal:
Array2D<float>data(10,20);
cout<<data[3][6]; // fine
Here data[3] yields an Array1D object and the operator [] invocation on that object yields the float in position(3,6) of the original two dimensional array. Clients of the Array2D class need not be aware of the presence of the Array1D class. Objects of this latter class stand for one-dimensional array objects that, conceptually, do not exist for clients of Array2D. Such clients program as if they were using real, live, two-dimensional arrays. Each Array1D object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. In the above example, Array1D is a proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not exist.
24.
Differences of C and C++
Could you write a small program that will compile in “C†but not in “C++�
In C, if you can a const variable e.g.
const int i = 2;
you can use this variable in other module as follows
extern const int i;
C compiler will not complain.
But for C++ compiler u must write
extern const int i = 2;
else error would be generated.
25.
What is the difference between Mutex and Binary semaphore?
semaphore is used to synchronize processes. where as mutex is used to provide synchronization between threads running in the same process
26.
What problem does the namespace feature solve?
Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link with two or more such libraries. The namespace feature surrounds a library’s external declarations with a unique namespace that eliminates the potential for those collisions.
This solution assumes that two library vendors don’t use the same namespace identifier, of course.
27.
Describe run-time type identification.
The ability to determine at run time the type of an object by using the typeid operator or the dynamic_cast operator.
28.
Amonog all the available IPCs, Shared Memory is the best and fastest one. We need to use Shared memory when more
than one proceses wish to communicate each other on a common read-only memory. It is fast because it does not
involve physical moment of data as the data is shared among them.
Mutex/Semaphore is the best when a resource(including memory) is non-shared
29.
What is the difference between dead-lock and live-lock
DEADLOCK Deadlock is a condition in which a task waits indefinitely for conditions that can never be satisfied - task claims exclusive control over shared resources - task holds resources while waiting for other resources to be released - tasks cannot be forced to relinguish resources - a circular waiting condition exists
LIVELOCK Livelock conditions can arise when two or more tasks depend on and use the some resource causing a circular dependency condition where those tasks continue running forever, thus blocking all lower priority level tasks from running (these lower priority tasks experience a condition called starvation).
A livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing. Livelock is a special case of resource starvation; the general definition only states that a specific process is not progressing.
A real-world example of livelock occurs when two people meet in a narrow corridor, and each tries to be polite by moving aside to let the other pass, but they end up swaying from side to side without making any progress because they both repeatedly move the same way at the same time.
Livelock is a risk with some algorithms that detect and recover from deadlock. If more than one process takes action, the deadlock detection algorithm can be repeatedly triggered. This can be avoided by ensuring that only one process (chosen randomly or by priority) takes action.
30.
Synchronous Sockets--( Blocking )--
A read on a socket can't complete until some data has been send by the remote host. If there is no data waiting to be read, one of two things can happen:
Function can wait until somedata is written on the socket. or
ASynchronous Sockets-- ( Non Blocking) - It can return immediately with an error that indicate that there is no data to be read.
31. Livelock-- A livelock is similar to a deadlock, except that the states of the processess invlolved in the livelock constantly change with regards to one another, none progressing .
Necessary condition of Deadlock-
Mutual exclusion- At least one resource must be held in a non-sharable mode,ONly one precess can use the resource at any given instant of time.
Hold and wait- A precess is currently holding at least one resource and requesting additional resource whic are being held by other process
No preemption-The Operating system must not de-allocate resource once they have been allocated; they must be released by the holding precess voluntarily.
Circular wait- A process must be waiting for a resourse with is being held by another process, which is turn is waithing for the first prcess to release the resources
32. Difference between structure and union:
Ans--
Structure
A structure allocates memory for each field in the structure.
We can access all the members of structure at anytime
All members of structure can be initialized.
'struct' keyword is used to declare structure..
Union:
A union only allocates enough memory to hold the largest field in the union.
Only one member of union can be accessed at anytime.
Only the first member of a union can be initialized.
'union' keyword is used to declare union.
--------Dead lock handling
1. Dead lock detection
( process termitation, resource preemption)
There are three general cases where the copy constructor is called instead of the assignment operator:
1.When instantiating one object and initializing it with values from another object
2.When passing an object by value
3. When an object is returned from a function by value.
33. So, using templates, we can write programs that do computation at compile time, such programs are called template metaprograms.
Example
#include <iostream>
using namespace std;
template<int n> struct funStruct
{
enum { val = 2*funStruct<n-1>::val };
};
template<> struct funStruct<0>
{
enum { val = 1 };
};
int main()
{
cout << funStruct<8>::val << endl;
return 0;
}
Output:
256
34. What is vitural base class.
Ans-- When we use virtual base class, then we get only one single instance of common base class.
35. Parameter passing in overloading. (like arry, pointer, etc).
36. 'Is-a relationship'-- It use public inheritance. (Ex-- every operation applied on employee will be applied on Manager)
37. 'Has-a relationship' -- It use private inheritance. ( Ex. Car has Wheel) -- class car : private wheel
38.Solving the Diamond Problem with Virtual Inheritance.
Example:
class transmitter: public virtual storable
{
public:
void read();
...
}
class receiver: public virtual storable
{
public:
void read();
...
}
When we use virtual inheritance, we are guaranteed to get only a single instance of the common base class. In other words, the radio class will have only a single instance of the storable class, shared by both the transmitter and receiver classes. By having a single instance of storable, we've resolved the compiler's immediate issue, the ambiguity, and the code will compile fine.
Memory Layout in Virtual Inheritance
In order to keep track of the single instance of the storable object, the compiler will provide a virtual function table (vtable) for classes transmitter and receiver. When a radio object is constructed, it creates one storable instance, a transmitter instance and a receiver instance. The transmitter and receiver classes have a virtual pointer in their vtables that stores the offset to the storable class. When the transmitter class or the receiver class goes to access any fields of the storable, it uses the virtual pointer in its vtable to find the storable object and find the field in it. This tutorial offers a comprehensive explanation of the memory layout of virtual inheritance in GCC.
--------------------------
Question:
1. paging
3. parameter of ( send and recv)
4. file ( go to particular location)
5. why malloc will return void *
6. Dangling pointer
Deep copy:-
It's equivalent to B* b3 = b2. The pointers will point to the same location. When you do delete b2;, you're also freeing the memory pointed to by b3.
To do a deep copy, do:
B* b3 = new B(*b2);
-------------------------------------------------
1. What is the output of printf("%d")
2. Difference between "C structure" and "C++ structure".
3. Difference between a "assignment operator" and a "copy constructor"
4. What is the difference between "overloading" and "overriding"?
5. Explain the need for "Virtual Destructor".
6. Can we have "Virtual Constructors"?
7. What are the different types of polymorphism?
8. What are Virtual Functions? How to implement virtual functions in "C"
9. What are the different types of Storage classes?
10. What is Namespace?
11. What are the types of STL containers?.
12. Difference between "vector" and "array"?
13. How to write a program such that it will delete itself after execution?
14. Can we generate a C++ source code from the binary file?
15. What are inline functions?
16. Talk something about profiling?
17. How many lines of code you have written for a single program?
18. What is "strstream" ?
19. How to write Multithreaded applications using C++?
20. Explain "passing by value", "passing by pointer" and "passing by reference"
21. Write any small program that will compile in "C" but not in "C++"
22. Have you heard of "mutable" keyword?
23. What is a "RTTI"?
24. Is there something that I can do in C and not in C++?
25. Why preincrement operator is faster than postincrement?
26. What is the difference between "calloc" and "malloc"?
27. What will happen if I allocate memory using "new" and free it using "free" or
allocate sing "calloc" and free it using "delete"?
28. What is Memory Alignment?
29. Explain working of printf.
30. Difference between "printf" and "sprintf".
31. What is "map" in STL?
32. When shall I use Multiple Inheritance?
33. What are the techniques you use for debugging?
34. How to reduce a final size of executable?
35. Give 2 examples of a code optimization.
-----------------------------------------------