Solution:
Solution A.
assign 25 to byte no. 4
*((char*)ptr+4)=25
assign 45 to byte no. 9
*((char*)ptr-1)=45
B. Write the total number of read and write operations against each statement, whereas num is integer array and ptr is integer pointer.
S.No. Statements Read Operation Write Operation
1 **ptr=4;
2 *(num+3);
3 num= 67;
4 ***ptr=100;
5 *(ptr+4)=8;
Solution:
Read operations Write Operations
1 **ptr=4; 2 1
2 *(num+3); 0 1
3 num= 67; 0 1
4 ***ptr=100; 3 1
5 *(ptr+4)=8; ? ?
C. Convert the following array subscripts into indirection format:
i. P[7];
ii. L[4][3];
iii. M[1][2][3];
iv. H[3][i];
v. X[1][4][2][3];
Solution:
i. P[7];
Answer 1: *(p+7)
ii. L[4][3];
Answer ii : *(L+4)[3] then *(*(L+4) +3)
iii. M[1][2][3];
Answer iii : *(M+1)[2] [3] then *(*(M+1)+2)[3] then *(*(*(M+1)+2)+3)
iv. H[3][i];
Answer iv : *(H+3)[i] then *(*(H+3) +i)
v. X[1][4][2][3];
Answer v : *(X+1) [4][2][3] then *(*(X+1)+4)[2][3] then *(*(*(X+1)+4)+2)[3] then *(*(*(*(X+1)+4)+2)+3)
Solution A.
assign 25 to byte no. 4
*((char*)ptr+4)=25
assign 45 to byte no. 9
*((char*)ptr-1)=45
B. Write the total number of read and write operations against each statement, whereas num is integer array and ptr is integer pointer.
S.No. Statements Read Operation Write Operation
1 **ptr=4;
2 *(num+3);
3 num= 67;
4 ***ptr=100;
5 *(ptr+4)=8;
Solution:
Read operations Write Operations
1 **ptr=4; 2 1
2 *(num+3); 0 1
3 num= 67; 0 1
4 ***ptr=100; 3 1
5 *(ptr+4)=8; ? ?
C. Convert the following array subscripts into indirection format:
i. P[7];
ii. L[4][3];
iii. M[1][2][3];
iv. H[3][i];
v. X[1][4][2][3];
Solution:
i. P[7];
Answer 1: *(p+7)
ii. L[4][3];
Answer ii : *(L+4)[3] then *(*(L+4) +3)
iii. M[1][2][3];
Answer iii : *(M+1)[2] [3] then *(*(M+1)+2)[3] then *(*(*(M+1)+2)+3)
iv. H[3][i];
Answer iv : *(H+3)[i] then *(*(H+3) +i)
v. X[1][4][2][3];
Answer v : *(X+1) [4][2][3] then *(*(X+1)+4)[2][3] then *(*(*(X+1)+4)+2)[3] then *(*(*(*(X+1)+4)+2)+3)
No comments:
Post a Comment