Programming Languages Fundamentals

Quiz covering fundamental concepts in C, C++, and Java programming languages including operators, data structures, algorithms, and language-specific syntax.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

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
Question 2 Multiple Choice (Single Answer)

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
Question 3 Multiple Choice (Single Answer)

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
Question 4 Multiple Choice (Single Answer)

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
Question 5 Multiple Choice (Single Answer)

Which of the following is not a valid keyword:

  1. public
  2. protected
  3. guarded
  4. None of the Above
Question 6 Multiple Choice (Single Answer)

What is the correct syntax for inheritance?

  1. class aclass : public superclass
  2. class aclass inherit superclass
  3. class aclass <-superclass
  4. None of the Above
Question 7 Multiple Choice (Single Answer)

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
Question 8 Multiple Choice (Single Answer)

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

  1. Breaks out of the if statement
  2. Exits the function
  3. Nothing (Compiler error)
  4. None of the Above
Question 9 Multiple Choice (Single Answer)

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
Question 10 Multiple Choice (Single Answer)

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
Question 11 Multiple Choice (Single Answer)

Which is not valid in C?

  1. class aClass{public:int x;};
  2. /* A comment */
  3. char x=12;
  4. None of the Above
Question 12 Multiple Choice (Single Answer)

Which of the following is not a valid declaration for main()?

  1. int main()
  2. int main(int argc, char *argv[])
  3. They both work
  4. None of the Above
Question 13 Multiple Choice (Single Answer)

Evaulate the following: 22%5

  1. 2
  2. 4
  3. 0
  4. None of the Above
Question 14 Multiple Choice (Single Answer)

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

  1. True
  2. False
  3. Invalid Statement
  4. None of the Above
Question 15 Multiple Choice (Single Answer)

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
Question 16 Multiple Choice (Single Answer)

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
Question 17 Multiple Choice (Single Answer)

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;
Question 18 Multiple Choice (Single Answer)

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);
Question 19 Multiple Choice (Single Answer)

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
Question 20 Multiple Choice (Single Answer)

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