Safe Systems of Work

Submitted by: Submitted by

Views: 218

Words: 643

Pages: 3

Category: Science and Technology

Date Submitted: 04/09/2011 01:41 AM

Report This Essay

Q1 a) It has no return type. b) It must have a name the same as the class name. Q2 b) 007B1950 10 int *p = new int(10); means: int *p; p = new int; *p = 10; Q3 e) char *a[20]; array of pointers: a[0] = new char; // or &c, char c; ... a[19] = new char; Q4 a) p =&a; b) p = new int; c) p = new int[3]; d) p = q; q = address of int &q = address of (address of int) p = address of int p = &q, incorrect Q5 a) p = a; d) p = &a[0]; a &a[0] int *p; local variable p contains random data; *p may point to illegal location *p = a[0], run-time error &p = address of p &p = a[0], illegal Q6 b) 0, NULL int *p; p = 0 or p = NULL Q7 d) On initializing an array, it is an error if the number of initialized values is larger than the size of the array. e) When the name of an array is used as the passed parameter on function calling, the array elements are passed by reference. d) int a[2] = {1,2,3}, error e) fun(a), a is address a) array store a group of same type b) array index must be int c) int a[10]={1,2,3}, remaining elements are zero Q8 a) int *funcPtr1(int, char); d) int *Ptr=0; a) function prototype, input one int and one char return int pointer

d) int *Ptr; Ptr = 0 b) should be int *c[3] c) should be b[1][1]=5; Q9 e) void temp(int p[int]); e is illegal Q10 c) 4 all pointers are 32-bit or 4 bytes Q11 c) Created, Created, Created, Created, Destroyed, Destroyed, i = 0, Felix = new CAT[2], fired two constructors i = 1, Felix = new CAT[2], fired two constructors delete [] Felix, fired two destructors Q12 c) Yes, 8 bytes are not released. i = 0, Felix = new CAT[2] are not released one CAT is 4 bytes, two CAT = 8 bytes Q13 a) Felix->setAge(12); b) Felix[1].setAge(12); c) (Felix+1)->setAge(12); d) should be Felix[0].setAge(12) or (*Felix).setAge(12) e) means *( Felix->setAge(12) ) or *(void) Q14 a) Mary string1[0]=0, ... string[79]=0; after the break, i = 4 after strncpy, string1[0]='M', .. string1[3]='y' string1[4]=0; cout a[1] = a[0] + a[1] =12+2 = 14 *(p+1) = *(p-1) -> a[2] = a[0]...