What is a friend function? Use of friend and encapsulation are contradictory- common critically?

As per the concept when data is declared as private inside a class, it is not accessible from outside the class. A function that is not a member or an external class will not a member or an external class will not be able to access the private data. A programmer may have a situation where they would need to access private data from non-member functions and external classes.

Handing such cases the concept of the friend function is a useful tool. A friend function is used for accessing the non-public member of a class. A class can allow non-member functions and other classes to access its private data, by making them friends. Thus, a friend function is an ordinary function for a member of another class.

There is conduction between these two because the encapsulation comes about by hiding the details of how the class is implemented; you defined a public interface separately from a private implementation. A friend function is used for accessing the non-public members of a class. A class can allow non-member functions and other classes to access its private data, by making them friends.

What is a critical section?

Let us consider a system consisting of n processes(p0,p1…….pn-1). Each process has a segment of code, called a critical section. In which the process may be changing common variables updating a table, writing a file, and so on the important feature of the system is that when one process is executing in its critical section.

The array of objects.

An array of variables of the type class is called, the array of objects. An array of objects is stored inside the memory in the same way as a multi-dimensional array.

Copy constructor:

Copy constructor is a special type of constructor by which we can inicilited the data member of a newly created object by an already existing object of some class.

Friend function:

A function that although not a member of the class is able to access the private member of that class is called the friend function.

Rules for operator overloading|:

  1. Only existence overloaders can be overloaded. The new operator can not be heated.
  2. The overloaded operator must have at least one operant that is of user-defined type.
  3. We can not change the basic meaning of an operator. That is to substruct one value from the other.
  4. Overloaded operators follow the syntax rules of an original operator.
  5. The same operator that can not be overloaded(that is the size of,::? etc).
  6. We can not use the friend function to overload certain operators. However, member functions can be used to overload them.
  7. A unary operator, overloaded by means of a member function, takes no explicit argument and returns no explicit value.
  8. Binary operator overloading through a member function takes one explicit argument and those that are overloaded through a friend function take two explicit arguments.
  9. A binary arithmetic operator such as +, -, *, and / must explicitly return a value, they may not attempt to change their own arguments.

Different between if and switch case statements.

IfSwitch case
In a multi-way decision statement the complexity of the program increases.In the if-statement, the floating point condition can be checked and the integer, and character type condition also be checked.
In the if-statement, the floating point condition can be checked and the integer, character type condition also be checked.Only integer and character type constants can be checked.

Different between structure and array

StructureArray
The array is a pointer variable.The array is a collection of homogenous data.
The structure is used to develop user-defined data types.The structure is not a pointer variable.
The array uses a compiler-defined data type.Structure is used to develop user-defined data types.

What is the differences between virtual memory & cache memory?

Vartual memoryCache memory
Virtual memory is originally created in secondary memory.Cache memory marks the computer processing speed high.
Virtual memory marks the computer processing speed slowerCache memory markes the computer processing speed high.
Cost of the virtual memory is lower.The cost of cache memory is higher.
The storage capacity of virtual memory is higher.The storage capacity of cache memory is lower

What is a null pointer?

There are times when it’s necessary to have a pointer that does not point to anything. The macro null, defined in <stddef.h>, has a value that’s generated to be different from any valid pointer. Null is a literal zero, possible cost to void * or char*.

What is a command line argument?

In console-based c-program, we can pass arguments to the main method. The signature of the main method in such a case is-

argc- int main int agrc, char*argv[] where gives the count of the number of arguments passed.

argv- Holds the number of arguments entered it is required to convert or cast into required data types as argv can accept airing only.

The first element of argv[0] is the program names so you normally won’t be using that.

Difference between continue & break statement

ContinueBreak
Continued statements can not terminate the loop.Continued statements can noencounteredte the loop.
In the switch case statement break statement is used. The break statement terminates the loop.
In the switch case statement, the continue statement is not used.In switch case statement break statement is used.

Difference between Malloc & Calloc

MallocCalloc
The Malloc function allocates a signal block of storage space.Calloc function allocation multiple block of storage, each of some size.
Malloc function does not set all bytes to zero.Calloc function sets all bytes to zero.
Syntex: Ptr=(cost type*)
Malloc=(type size)
Syntex: ptr=(cost type *)
calloc(n-block, element size)

Difference between Global variable & External variable.

Global VariableExternal Variable
Global variables must be declared outside the function of a program.External variable can be declared inside the function.
Default value of Global variable may be Garbage.No keyword may be used before the global variable.
There is no keyword that may be used before the global variable.The external keyword must be used before external variable.

Difference between global variable & Local variable.

Global variableLocal variable
The global variable is declared outside the function of a c program.Local variable is declared inside the function of a c program
The global variable can be accessed by any function in a program.The local variable can be accessed by the function where it is declared.
Ex: int I;
main()
{
//code
}
Ex:main()
{
int I;
//code
}

Leave a Reply

Your email address will not be published. Required fields are marked *