- 1
Please solve my queries .
(1) i haven't understood 4 types of function. What should i do ? (2) also i haven't understood recursion . So should i leave it as it is first language and learn it in D.S.A. or what should i do ?
3 Answers
+ 2
A function is recursive ,if it calls itself repeated..
Like :
A() {
//..
A();
//..
}
You must put a condition to stop iteration. Otherwise it's infinite recursion. The condition is called a base condition.
What do mean by 4 types of functions there?
+ 2
Jayakrishnađźđł sir , 4 types means
(1) Both argument and return value .
(2) No argument but return value.
(3) argument but no return value.
(4) no argument and no return Both .
0
A function syntax :
A function contains function definition and function calling statements..
Function definition:
<return_type> function_name( arguments)
{
//body
}
return_type is any data type or void.
So function returns a value back to calling statement. If it is void means it does not return anything.
<argument> are a list of data values passed to functions. , in the form:
(<type> <name>, .......)
there may be any number of arguments from zero to n.
Hope you know, how to declare:
Ex:
Declaration:
void print(int i);
Definition:
void print(int i) {
printf("%d , Hello", i);
}
Calling : print(5);
(1) Both argument and return value .
int get(int i) {
return a[I];
}
//returns value at index I from array a.
(2) No argument but return value.
int pop() {
return a[0];
}
//returns value at index 0
(3) argument but no return value.
void display(char name[]) {
printf("%s", name) ;
}
//argument passed a character array. nothing returns
(4)no argument and no return Both .
void print(){
printf("hi");
}