0

programming languages Online Quiz - 275

Description: programming languages Online Quiz - 275
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

Will a C compiler always compile C++ code?

  1. Yes

  2. No

  3. Only optimized compilers will compile C++ code.

  4. None of the Above


Correct Option: B

What does the following code snippet do: for(;;) ;

  1. The snippet is illegal

  2. It loops forever

  3. It is ignored by compiler, but it is not illegal

  4. None of the Above


Correct Option: B

What does the code strcat(an_array, "This"); do?

  1. Copies "This" into an_array

  2. Adds "This" to the end of an_array

  3. Compares an_array and "This"

  4. None of the Above


Correct Option: B

Evaluate the following: int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; } for fn(7);

  1. 10

  2. 11

  3. 1

  4. None of the Above


Correct Option: B

Which of the following is not a valid keyword:

  1. public

  2. protected

  3. guarded

  4. None of the Above


Correct Option: C

What is the correct syntax for inheritance?

  1. class aclass : public superclass

  2. class aclass inherit superclass

  3. class aclass

  4. None of the Above


Correct Option: A

Of the numbers 12, 23, 9, and 28, which one would be at the top of a properly implemented maxheap?

  1. 28

  2. 9

  3. Any of them could be

  4. None of the Above


Correct Option: A

What does the line containing "break;" do in the following code? void afunction() { if(1) { break; a_function(); cout<

  1. Breaks out of the if statement

  2. Exits the function

  3. Nothing (Compiler error)

  4. None of the Above


Correct Option: C

If you push 1, 3, and 5 - in that order - onto a stack, which number is popped out first?

  1. 5

  2. 1

  3. 3

  4. None of the Above


Correct Option: A

Which of the following data structures is on average the fastest for retrieving data:

  1. Binary Tree

  2. Hash Table

  3. Stack

  4. None of the Above


Correct Option: B

Which is not valid in C?

  1. class aClass{public:int x;};

  2. /* A comment */

  3. char x=12;

  4. None of the Above


Correct Option: A
  1. int main()

  2. int main(int argc, char *argv[])

  3. They both work

  4. None of the Above


Correct Option: C

Evaulate the following: 22%5

  1. 2

  2. 4

  3. 0

  4. None of the Above


Correct Option: A

Evaluate the following as true or false: !(1 &&0 || !1)

  1. True

  2. False

  3. Invalid Statement

  4. None of the Above


Correct Option: A

Which command properly allocates memory?

  1. char *a=new char[20];

  2. char a=new char[20];

  3. char a=new char(20.0);

  4. None of the Above


Correct Option: A

Would you rather wait for the results of a quicksort, a linear search, or a bubble sort on a 200000 element array?

  1. Quicksort

  2. Linear Search

  3. Bubble Sort

  4. none of the above


Correct Option: B

Q: 1 Given: 11. public class Person { 12. private String name, comment; 13. private int age; 14. public Person(String n, int a, String c) { 15. name = n; age = a; comment = c; 16. } 17. public boolean equals(Object o) { 18. if (! (o instanceof Person)) return false; 19, Person p = (Person)o; 20. return age == p.age && name.equals(p.name); 21. } 22. } What is the appropriate definition of the hashCode method in class Person?

  1. A. return super.hashCode();

  2. B. return name.hashCode() + age * 7;

  3. C. return name.hashCode() + comment.hashCode() / 2;

  4. D. return name.hashCode() + comment.hashCode() / 2 - age * 3;


Correct Option: A

2 Given: 34. HashMap props = new HashMap(); 35. props.put("key45", "some value"); 36. props.put("key12", "some other value"); 37. props.put("key39", "yet another value"); 38. Set s = props.keySet(); 39. // insert code here What, inserted at line 39, will sort the keys in the props HashMap?

  1. A. Arrays.sort(s);

  2. B. s = new TreeSet(s);

  3. C. Collections.sort(s);

  4. D. s = new SortedSet(s);


Correct Option: B

for (printf("a");printf("b");printf("c")) { break; } What will be the output of the above code snippet?

  1. ab

  2. abc

  3. c

  4. none of the above


Correct Option: A

i=3; Printf("%d%d%d",i++,++i,i); What will be output of the code snippet?

  1. 345

  2. 456

  3. 344

  4. 443


Correct Option: D
- Hide questions