You are on page 1of 2

Programming Techniques Sheet #1

CMP 103 & CMP N103 1/2 Spring 2014




1. Consider the following piece of code







Assume that the array "A" is stored at address 100 and the size of the int is 4 bytes.
Complete the following table:

Item Value Item Value
A B
&A[0] C
*A C - B
A[0] B[0]
*&A[0] C[2]
&*A *(B+1)
A[0]+7 *B+1
*(A+7) *(&C[1]+1)
&A[2] *&C[1]+1
&A[6] *A**B**C


2. What is the output of the following piece of code?
a.







3. What is the problem with the following pieces of code?
a.






b.







Cairo University
Faculty of Engineering
Computer Engineering Department

Programming Techniques
Sheet #1
int A[10] = {1, 10, 20, 30, 40, 50, 60, 70, 80, 90};
int *B;
int *C;
B = &A[2];
C = A+6;

int A[5] = {0, 1, 2, 3, 4};
int M[5] = {5, 6, 7, 8, 9};
int *P;
P=M;
A=P;
int* f()
{
int x=90;
int *p=&x;
return p;
}

int A[5] = {0, 1, 2, 3, 4};
for(int* P=A; *P<4; P++
cout<<P<<"\t"<<*P<<endl;
//Assume Array A is stored at address 100.
Programming Techniques Sheet #1

CMP 103 & CMP N103 2/2 Spring 2014















4. Write a function AlternateSplit that takes an array A of size n and splits it into two arrays B and
C. Your function should
a. Create two dynamic arrays B and C.
b. Copy elements from arrays A to B and C alternatively.
Note: don't use the notation Array_name[index] to copy array elements.
c. Free the array A.


5. Write a function that swaps two dynamically allocated arrays (with equal sizes) but without
actually copying array elements from one place to another.

1) int x, y;
2) const int !=30;
3) int * q;
4) int * const p = &x;
5) const int * r;
6) p = &y;
7) r = &y;
8) *" = 7;
9) *r = 9;
10) *# = 40;
11) !=$0;
12) q = &z;
13) r = &z;

You might also like