Week 6 Flashcards

1
Q

4 jenis passing parameters?

A
  1. passing by value
  2. passing by address
  3. passing by reference
  4. passing by const reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is reference?

A

reference adalah alias or synonym for another variable. server as alternative name for an object. harus di inisialisasi pada saat declared. Ex: int &count.

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

Perbedaan pointer dengan reference?

A

Pointer:

  1. tidak perlu diinisialisasikan pada saat definisi
  2. dapat di assign nilai baru untuk object yang berbeda

Reference:

  1. harus diinisialisasikan pada saat definisi
  2. selalu refer ke object yang sama
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

a constant reference variable var?

A

refer ke object yang nilai yang tidak dapat di ganti dengan var.

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

r is a reference for n?

A

int& r = *p;

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

operator * disebut?

A

dereferencing operator

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

3 jenis memory?

A
  1. static memory untuk global dan static variables live
  2. heap memory dialokasikan secara dinamis pada saat execution time. (unnamed variable)
  3. stack memory untuk automatic variable dan function parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

3 jenis program data?

A
  1. static data, dialokasikan pada saat compiler time
  2. dynamic data, secara explicit di alokasikan dan deallocated pada saat program execution. dengan operator new and delete
  3. automatic data, secara otomatis dibuat pada function entry dan di hancurkan pada saat kembali ke function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

dangling pointer?

A

a pointer that does not point to anything. uninitialized and de-allocated pointer

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

contoh dangling pointer?

A

int *p = new int;

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

contoh passing by value?

A
void calculate (int a, int b){
       a = a+1;
       int c = a + b;
       cout << "c = " <<endl;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

contoh passing by address?

A
void calculate
       *a = *a+1;
       int c = *a + *b;
       cout << "c = " <<endl;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

contoh passing by reference?

A
void swap(int& x, int& y) {
   int temp = x;
   x = y;
   y = temp;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

contoh passing by const reference?

A
void calculate
        a = a+1; //error : cannot modify const object
        int c = a + b;
        cout << "c = " <<endl;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly