Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
24 views2 pages

Homework ADS

Pass-by-value sends a copy of the actual parameter so the parameter cannot be changed in the function, while pass-by-reference sends the memory address allowing the parameter to be modified. Structs are a built-in composite data type that allows grouping of different data types under one name. The virtual address of array element a[3] is calculated as the base address plus the index multiplied by the element size.

Uploaded by

Yahya Buharali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Homework ADS

Pass-by-value sends a copy of the actual parameter so the parameter cannot be changed in the function, while pass-by-reference sends the memory address allowing the parameter to be modified. Structs are a built-in composite data type that allows grouping of different data types under one name. The virtual address of array element a[3] is calculated as the base address plus the index multiplied by the element size.

Uploaded by

Yahya Buharali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Yahya Buharali - 202211003

1. Compare by a method example between pass-by-value and pass-by-references ?

Pass-by-value

sends a copy of the contents of the actual parameter

So, the actual parameter cannot be changed by the function.

#include <iostream.h>

void Fun(int a);

int main(){
the value of the x stays the same in the
int x = 5; main function which is 5

Fun(x);

cout << x;

return 0;

void Fun(int a){

a = a * 2;
and here after the calculation, x
} equals to 10

Pass-by-reference

sends the location (memory address) of the actual parameter

So, can change value of actual parameter

#include <iostream.h>

void Fun(int &a);


the value of the x can be changed by
int main(){ the calling function using the and sign
int x = 5;

Fun(x);

cout << x;

return 0;

void Fun(int &a){

a = a * 2;

}
2. To which the struct belongs to: built in composite data type.

2.1 Address

2.2 Simple

2.3 Composite

3. Complete the following ( given; base address= 20, integer size=2, column size =6)

3.1 The virtual address of a[3] is 32

A[3] = base address + index * size

= 20 + 3 * 4

= 20 + 12

= 32

3.2 The virtual address of a[3][2] is not found.

You might also like