50 muliple choice questions of object oriented programming

10
50 Muliple choice questions of Object Oriented Programming

Upload: devanabha

Post on 08-Apr-2015

475 views

Category:

Documents


1 download

TRANSCRIPT

50 Muliple choice questions of Object Oriented Programming

1. Which of the following is a Scalar Data type?

a) Floatb) Pointerc) Arraysd) Union

2. Which of the following is invalid?a) ‘ ’b) “ ”c) ‘a’d) ‘abc’

3. When a key is pressed on the keyboard, which standard is used for converting the keystroke into the corresponding bits on windows platform?

a.) ANSIb. ) ASCIIc.) ISOd. ) EBCDIC

4. Which of the following is an example of compounded assignment statement?

a) a = 5b) a += 5c) a = b = cd) a = b

5. Operators have hierarchy. It is used to know which operator

a) is most important

b) is used firstc) is fasterd) operates on large numbers

6. The Worst case occur in linear search algorithm when

a) Item is somewhere in the middle of the array

b) Item is not in the array at allc) Item is the last element in the arrayd) Item is the last element in the array

or is not there at all

7. p++ executes faster than p+1 becausea) p uses registersb) p++ is a single instructionc) ++ is faster than +d) None of these

8. The printf() function retunes which value when an error occurs?

a) Positive valueb) Zeroc) Negative valued) None of these

9. What is the first change that selection sort would make to this sequence to put it into ascending order: "3 1 4 2"?

a) 1 3 4 2b) 2 4 1 3c) 3 2 4 1d) 4 2 3 1

10. A linked list index is ____ that represents the position of a node in a linked list.

a) an integer b) a variable c) a character d) a Boolean

11. The C complier provides the DEBUG complier option and its sub-options to control the following actions:-

a) The generation and placement of hooks and symbol tables.b) The placement of debug information

into the object file or separate debug file.c) both a and bd) None of these.

12. Identify the invalid pointer arithmetica) Addition of float value to a pointerb) Comparison of pointers that do not point to the element of the same array.c) Subtracting an integer from a pointer.d) Assigning the value 0 to a pointer variable .

13. A Structurea) can be read as a single entityb) cannot be read as a single entityc) can be displayed as a single entityd) has member variables that cannot be read individually.

14. When the main function is called, it is called with the arguments

a) Argcb) Argvc) None of thesed) both a & b

15. A Link isa) a Compilerb) a C interpreterc) an analyzing tool in Cd) an active debugger

16. Which is of the below is not a benefit of using a linked list instead of an array?

a) Linked list is more flexibleb) Linked list allow you sort the elements more easily.c) Linked list allow you to randomly access one of its elements.d) All of the above are its benefits

17. What is the output of the following program, if its command line arguments were 1 5 7.

int main(int argc, char *argv[]) {

   int x;   x = argv[1] + argv[2] + argv[3];   printf ("%d", x);

}a) Error: invalid pointer addition b) 1,5,7c) 7,5,1d) 5,1,7

18. Value of the first linked list index is a) oneb) zeroc) -1d) None of these

19. What is the output of the following program?

void main() {   char s1[] = "Hagrid";   char s2[] = "Hagrid";   if (s1==s2)      printf ("Same");   else     printf ("Different");

} a) Sameb) Differentc) Conditional Errord) None of these

20. What is output of following program when we compile and run it?

void main( ) { int const * p=5; printf("%d",++(*p)); }

a) 25b) 6c) Compiler error: Cannot modify a constant value.d) 30

21. What is output of following? void main() { char s[ ]="man"; int i; for(i=0;s[i];i++) printf("\n%c%c%c%c",s[i],*(s+i),*(i+s),i[s]); }

a) mmmm aaaa nnnnb) mmmm aaa nnnnc) man man mand) error

22. 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?

a) 3b) 5c) 11d) 9

23. f = fopen( filename, "r" ); Referring to the code above, what is the proper definition for the variable f ?

a.FILE f;b. FILE *f;c.FILE **f;d. FILE int f;

24. int x[] = { 1,4,8,5,1,4 }; int *ptr, y; ptr = x+4; y = ptr-x;

What does y in above code equal?a) -3b) 0c) 4d) 4 + sizeof(int)

25. Which of these is the best tool for finding unsafe library function calls?

a) The warning message of the C compiler.

b) A debuggerc) A static analyzerd) All of the above.

26. int i , j ; int ctr = 0;

int myArray[2][3];for(i=0;i<3;i++)for (j=0;j<2;j++){myArray[j][i]=ctr ;++ctr;}

What is the value of myArray[1][2]; in the sample code above?

a) 1b) 2c) 5d) 00,10,01,11,12

27. Which one of the following is valid for opening a read-only ASCII file?

a) fileOpen (filenm, "r");b) fopen (filenm, "ra");

c) fileOpen (filenm, "read");d) fopen (filenm, "r");

28. When is insertion sort, a good choice for sorting an array?a) Each component of the array

requires a large amount of memory.b) Each component of the array

requires a small amount of memory.c) The array has only a few items out

of place.d) The processor speed is fast.

29. Given the statement,maruti.engine.bolts = 25;

Which of the following is true ?a)Structure bolts is nested within structure engine.b) Structure engine is nested within structure maruti.c) Structure maruti is nested within structure engine.

d) Structure maruti is nested within structure bolts.

30. char *m[] = { “Chandu Ke Chacha Ne”,

“Chandu Ki Chachi Ko”, “Chaandi Ki Chamach Se”, “Chutney Chataai !!!!!!” };

void main( ) {

int i;for(i=0,i<=3;i++)

Printf(“\n%s”,m[1]); }

a) Chandu Ke Chacha Ne Chandu Ki Chachi Ko

Chaandi Ki Chamach Se Chutney Chataai!!!!!!

b) Chandu Ki Chachi Ko Chandu Ki Chachi Ko Chandu Ki Chachi Ko Chandu Ki Chachi Ko

c) Chaandi Ki Chamach Se Chaandi Ki Chamach Se Chutney Chataai

Chutney Chataai

d) All of the above31. What is the output?

int main( ){ struct num { int x,y; } val[4] = { 1,1,2,3,4,5,6,7}; struct num *ptr = val; int i = 0; for(;i<4;i++) { ptr->x = ptr->y, ++ptr++->y;  printf("%d,%d ", val[i].x, val[i].y); }}a) 1,3,2,5,4,7,6,9b) Undefined behaviorc) 1,2,3,4,5,6,7,8d) Segmentation fault

32. What does "typedef unsigned int Uint;" do?

a) it is ignored by the compilerb) it renames an unsigned integer data type as Uintc) it causes a compiler errord) it renams an integer data type as Uint.

33. The output will beint main()

{ int i = 5, j = 2; junk (&i, &j); printf(“\n %d %d”,i,j);

} junk ( int *i, int *j) { *i = *i **i; *j = *j**j; }a) 25 , 4b) 25, 2c) 5, 4d) 5, 2

34. Select the proper order of events. a) Debug program, write results, load

program, describe objective, run program, record results.

b) Describe objective, write program, record results, load program, debug program, , run program

c) Run program, record results, load program, describe objective, record results, debug program.

d) Describe objective, write program, debug program, load program, run program, record results.

35. What will be output of following program?

#include “stdio.h”void main( ){char *str="i know u .";clrscr( );while(*str) {

putc(*str,stdout);fputchar(*str);printf("%c",*str);str++;

}getch();}a) iii kkknnnooowww uuu ...b) iiiiii knowwwwwwwwww uuuuuuu c) ii kknnooww uu ..d) None of the above

36. What will be the output of program (days), if it is executed from the command line as shown below?

days friday tuesday Sunday

/* days*/# include<stdio.h>void main (int argc, char *argv[]){ while(--argc>0)

printf(“%s”,*++argv);}

a) days friday tuesday sundayb) friday tuesday sundayc) days tuesday sundayd) None of the above

37. void main( ){ unsigned char ch; FILE *fp;/* ABC.C exists and contains “Kicit 44-a Gokulpeth\0 nagpur”*/fp = fopen ( “abc.c”, “r”);if (fp = = NULL){ printf (“Unable to open the file”); exit (1);}while( ( ch = getc (fp))!=EOF)printf (“%c”,ch);fclose(fp);}a) Kickt 44-a Gokulpeth nagpurb) Kickt 44-a Gokulpethc) Infinite Loopd) None of the above

38. Which function call will you add to the following program to write the entire structure into the file?

void main( ){ struct rain _details {

char city[10];float raininmm;

}; struct rain_details r = { “Banglore”, 40.5 }; FILE *fp; Fp = fopen (“rain.dat”, “wb”); /* add function call here */ fclose (fp);

a) fread (&r, sizeof ( r ),1,fp);b) fwrite (&r, sizeof ( r),1,fp);c) fwrite (&w, sizeof( w),1,fp);d) fread (&w, sizeof( w),1,fp);

39. An expression contains relational, assignment and arithmetic operators. If

parenthesis is not present, the order will be:- a) Assignment, arithmetic, relational b) Relational, arithmetic, assignment c) Assignment, relational, arithmetic d) Arithmetic, relational, assignment

40. Which of the following gives the memory address of a pointer a?

a) *a;b) a;c) &a;d) Address(a);

41. In C, arrays and pointers can always be used interchangeably.a) Trueb) False

42. In a group of nested loops, which loop is executed the most number of times?

a) the outermost loopb) the innermost loopc) all loops are executed the same number of

timesd) cannot be determined without knowing the

size of the loops

43. What is the index number of the last element of an array with 29 elements?

a) 29b) 28c) 0d) 27

44. Which of the following gives the memory address of the first element in array foo, an array with 100 elements?

a) foo[0];b) foo;c) &foo;d) foo[1];

45. What is the output of the following program?

main () { struct emp {         char name[20];

         int empno;} }; struct emp e1 = {"harrypotter", 1311}; struct emp e2 = e1;   if (e1==e2)        printf ("e1 and e2 are same");   else       printf ("e1 and e2 are different");}

a) illegal structure operation errorb) e1 and e2 are samec) e1 and e2 are differentd) none of these

46.Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?

a) int *ptr = (int *) malloc(10, sizeof(int));b) int *ptr = (int *) calloc(10, sizeof(int));c) int *ptr = (int *) malloc(10*sizeof(int));d) int *ptr = (int *) calloc(10*sizeof(int));

47. What is the output

int main() {  int x=0;  for(;x<20 && printf("%d ",x);x++)  switch(x) {   case 0:x++,x*=2;   case 1:x+=2;   case 99:x+=6;   default:x+=3;   break;   }}

a) 0 12 16b) 0 13 17c) 0 14 18d) 0 11 15 18

48. What is the output

void main() { char *s[]={ "miller","miller","filler","filler"}; char **p; p=s; printf("%s ",++*p); printf("%s ",*p++); printf("%s ",++*p);}

a) iller miller illerb) iller miller fillerc) iller iller fillerd) iller iller iller

49. char ** array [12] [12][12]; Consider array, defined above. Which one of the following definitions and initializations of p is valid?

a) char ** (* p) [12][12] = array;b) char ***** p = array;c) char * (* p) [12][12][12] = array;d) char (** p) [12][12] = array;

50. What will be the output when following code is executed int a=10,b; b=a++ + ++a; printf("%d,%d,%d,%d",b,a++,a,++a);

a) 22,13,13,13 b) 22,10,11,13c) 22,11,11,11d) 22,11,13,14