Oct 28 2022 Flashcards
1
Q
Why do we need template functions
A
You can write multiple functions together if the only difference is in data type
2
Q
What is the syntax of template/generic functions
A
template<class>
T maxim(T a,T b){
return a>b?a:b;
}</class>
3
Q
What are the types of parameter passing
A
By Value
By Address
By Reference
4
Q
What is the syntax of passing by address
A
Void swap(int *x, int y) {
int temp; temp=x; x=y; *y=temp;
}
Int main() {
int a=10, b=20;
swap(&a,&b);
cout«a«b; }
5
Q
What is the syntax of passing by reference
A
Void swap(int &a, int &b) {
int temp; temp=a; a=b; b=temp;
}
Int main() {
int x=10, y=20;
swap(x,y);
cout«x«y; }