Computer Science, asked by abreddy8131, 11 months ago

Difference. Between constructive and normal fumction

Answers

Answered by sanju5956
0

Functions

Functions are named unit/section of a program which performs a specific task, (say adding two numbers, calculating factorial etc.) and can be called in the region of scope.

It returns a value of a particular data type (if you don't wan to return a value make the return type of function as void).

Example:

//A function to calculate and return factorial

float fatorial(int n) {

float fact = 1;

for (int i = 1; i<=n; i ++) {

fact *= i;

}

return fact;

}

Constructors and destructors are member functions of class.

Constructor

Constructor is a member function of a class which is automatically called (unlike normal functions, which are needed to be called by the programmer) when an object of that particular class is created.

They do not return a value, not even void.

Even if the programmer does not create a constructor the compiler defines one for him.


sanju5956: hope this is helpful for u
Similar questions