Final C questions 01

Final C questions 01 - *questionnumber1 Code int...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
/*question number 1*/ 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?  Choice 1 Choice 2 Choice 3 10 [Ans] Corrected by buddy by running the program Choice 4 11  Choice 5 12  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 2*/ With every use of a memory allocation function, what function should  be used to release allocated memory which is no longer needed?  Choice 1 unalloc()  Choice 2 dropmem()  Choice 3 dealloc()  Choice 4 release()  Choice 5 free() [Ans]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 3*/ Code: void *ptr; myStruct myArray[10]; ptr = myArray; Which of the following is the correct way to increment the variable  "ptr"?  Choice 1 ptr = ptr + sizeof(myStruct); [Ans] Choice 2 ++(int*)ptr;  Choice 3 ptr = ptr + sizeof(myArray);  Choice 4 increment(ptr);  Choice 5 ptr = ptr + sizeof(ptr);  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 4*/ Code: char* myFunc (char *ptr) { ptr += 3; return (ptr); } int main() { char *x, *y; x = "HELLO";
Background image of page 2
y = myFunc (x); printf ("y = %s \n", y); return 0; } What will print when the sample code above is executed?  Choice 1 y = HELLO  Choice 2 y = ELLO  Choice 3 y = LLO  Choice 4 y = LO [Ans] Choice 5 x = O  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 5*/ 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 below accurately describes how it will work?  Choice 1 It will work correctly since the for loop covers the entire list.  Choice 2 It may fail since each node "nPtr" is freed before its next address can  be accessed. 
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Choice 3 In the for loop, the assignment "nPtr=nPtr->next" should be changed  to "nPtr=nPtr.next".  Choice 4 This is invalid syntax for freeing memory.  Choice 5 The loop will never end.  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 6*/ What function will read a specified number of elements from a file?  Choice 1 fileread()  Choice 2 getline()  Choice 3 readfile()  Choice 4 fread() X Choice 5 gets() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 7*/ "My salary was increased by 15%!"  Select the statement which will EXACTLY reproduce the line of text  above.  Choice 1 printf("\"My salary was increased by 15/%\!\"\n");  Choice 2 printf("My salary was increased by 15%!\n"); 
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/21/2010 for the course MATH C01 taught by Professor Dangcau during the Spring '10 term at Founders College.

Page1 / 65

Final C questions 01 - *questionnumber1 Code int...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online