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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the types of parameter passing

A

By Value
By Address
By Reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly