Sie sind auf Seite 1von 4

BIDVERTISER SUNDAY, AUGUST 1, 2010 CSA2P02-PROGRAMMING 1) void *ptr; myStruct myArray[10]; ptr=myArray; Which of the following is the correct

way to increment the variable "ptr"? v) ptr = ptr + sizeof(myStruct); w) ptr = ptr + sizeof(ptr); x)ptr = ptr + sizeof(myArray); y)increment(ptr); 2)By default any real number is treated as v) a float w) a double x) a long double y) Depends upon the memory model that you are using. 3) What is the output of the following program? main() { unsigned int a,b,c,d,e; a = b = 32; a <<= 2; b >>= 2; printf("\n %x %x ",a,b); } v)32 32 w)128 8 x)80 8 y)0 0 4) What is the output of the following program? main() { static char str[]= Limericks ; char *s; s=&str[6]-6; while(*s) printf( %c ,*s++); } v)k w)ks x)Limericks y)error 5) What is the output of the following program? main() { struct node { int data; struct node *link; }; struct node *p,*q; p=malloc(sizeof(struct node)); q=malloc(sizeof(struct node)); p->data=30; p->link=q; q->data=40; q->link=NULL; printf( %d ,p->data); p=p->link; printf( %d ,p->data); } v) 40 30 w)30 40 x)30 30 y)none 6) int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

What value does testarray[2][1][0] in the sample code above contain? v) 3 w)5 x)7 y)11 7) 11 ^ 5 What does the operation shown above produce? v) 55 w) 6 x)14 y) 161051 8)code: int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a; What number will z in the sample code above contain? v)5 w)6 x)10 y)11 z)12 9) With every use of a memory allocation function, what function should be used to release allocated memory which is no longer needed? v)unalloc() w)dropmem() X)dealloc() y)release() z)free() 10) Code: void *ptr; myStruct myArray[10]; ptr = myArray; Which of the following is the correct way to increment the variable "ptr"? v)ptr = ptr + sizeof(myStruct); w)++(int*)ptr; x)ptr = ptr + sizeof(myArray); y)increment(ptr); z)ptr = ptr + sizeof(ptr); 11)What function will read a specified number of elements from a file? v)fileread() w)getline() x)readfile() y)fread() z)gets() 12."My salary was increased by 15%!" Select the statement which will EXACTLY reproduce the line of text above. v)printf("\"My salary was increased by 15/%\!\"\n"); w)printf("My salary was increased by 15%!\n"); x)printf("My salary was increased by 15'%'!\n"); y)printf("\"My salary was increased by 15%%!\"\n"); z)printf("\"My salary was increased by 15'%'!\"\n");

13. What is a difference between a declaration and a definition of a variable? v)Both can occur multiple times, but a declaration must occur first. w)There is no difference between them. x)A definition occurs once, but a declaration may occur many times. y)A declaration occurs once, but a definition may occur many times. z)Both can occur multiple times, but a definition must occur first. 14. int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; What value does testarray[2][1][0] in the sample code above contain? v)3 w)5 x)7 y)9 z)11 15)Code: int a=10,b; b=a++ + ++a; printf("%d,%d,%d,%d",b,a++,a,++a); what will be the output when following code is executed v)12,10,11,13 w)22,10,11,13 x)22,11,11,11 y)12,11,11,11 z)22,13,13,13

16.Code: int x[] = { 1, 4, 8, 5, 1, 4 }; int *ptr, y; ptr = x + 4; y = ptr - x; v)-3 w)0 x) 4 y) 4 + sizeof( int ) z)4 * sizeof( int 17)Code: void myFunc (int x) { if (x > 0) myFunc(--x); printf("%d, ", x); } int main() { myFunc(5); return 0; } What will the above sample code produce when executed? v) 1, 2, 3, 4, 5, 5, w) 4, 3, 2, 1, 0, 0, x)5, 4, 3, 2, 1, 0, y)0, 0, 1, 2, 3, 4, z) 0, 1, 2, 3, 4, 5, 18. code: int x[] = { 1, 4, 8, 5, 1, 4 }; int *ptr, y; ptr = x + 4; y = ptr - x; What does y in the sample code above equal? v)-3 w)0 x)4 y)4 + sizeof( int ) z)4 * sizeof( int 19. code: . int a=10,b; b=a++ + ++a; printf("%d,%d,%d,%d",b,a++,a,++a); what will be the output when following code is executed v)12,10,11,13 w)22,10,11,13 x)22,11,11,11 y)12,11,11,11 z)22,13,13,13 20. Code: struct node *nPtr, *sPtr; /* pointers for a linked list. */ for (nPtr=sPtr; nPtr; nPtr=nPtr->next) { free(nPtr); } The sample code above releases memory from a linked list. Which of the choices b elow accurately describes how it will work? v)It will work correctly since the for loop covers the entire list. w)It may fail since each node "nPtr" is freed before its next address can be acc essed. x)In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=n Ptr.next". y)This is invalid syntax for freeing memory. z)The loop will never end.

Answers: 1) v) 2) w) 3) x) 4) x) 5) w) 6) y) 7) x) 8) x) 9) z) 10) v) 11) y) 12) Y) 13) Y) 14) Z) 15) Z) 16) X) 17) Y) 18) X) 19) Z) 20) W)

Das könnte Ihnen auch gefallen