Programming Languages Fundamentals
Quiz covering fundamental concepts in C, C++, and Java programming languages including operators, data structures, algorithms, and language-specific syntax.
Questions
Will a C compiler always compile C++ code?
- Yes
- No
- Only optimized compilers will compile C++ code.
- None of the Above
What does the following code snippet do: for(;;) ;
- The snippet is illegal
- It loops forever
- It is ignored by compiler, but it is not illegal
- None of the Above
What does the code strcat(an_array, "This"); do?
- Copies "This" into an_array
- Adds "This" to the end of an_array
- Compares an_array and "This"
- None of the Above
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);
- 10
- 11
- 1
- None of the Above
Which of the following is not a valid keyword:
- public
- protected
- guarded
- None of the Above
What is the correct syntax for inheritance?
- class aclass : public superclass
- class aclass inherit superclass
- class aclass <-superclass
- None of the Above
Of the numbers 12, 23, 9, and 28, which one would be at the top of a properly implemented maxheap?
- 28
- 9
- Any of them could be
- None of the Above
What does the line containing "break;" do in the following code? void afunction() { if(1) { break; a_function(); cout<<"Err"; } }
- Breaks out of the if statement
- Exits the function
- Nothing (Compiler error)
- None of the Above
If you push 1, 3, and 5 - in that order - onto a stack, which number is popped out first?
- 5
- 1
- 3
- None of the Above
Which of the following data structures is on average the fastest for retrieving data:
- Binary Tree
- Hash Table
- Stack
- None of the Above
Which is not valid in C?
- class aClass{public:int x;};
- /* A comment */
- char x=12;
- None of the Above
Which of the following is not a valid declaration for main()?
- int main()
- int main(int argc, char *argv[])
- They both work
- None of the Above
Evaulate the following: 22%5
- 2
- 4
- 0
- None of the Above
Evaluate the following as true or false: !(1 &&0 || !1)
- True
- False
- Invalid Statement
- None of the Above
Which command properly allocates memory?
- char *a=new char[20];
- char a=new char[20];
- char a=new char(20.0);
- None of the Above
Would you rather wait for the results of a quicksort, a linear search, or a bubble sort on a 200000 element array?
- Quicksort
- Linear Search
- Bubble Sort
- none of the above
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?
- A. return super.hashCode();
- B. return name.hashCode() + age * 7;
- C. return name.hashCode() + comment.hashCode() / 2;
- D. return name.hashCode() + comment.hashCode() / 2 - age * 3;
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?
- A. Arrays.sort(s);
- B. s = new TreeSet(s);
- C. Collections.sort(s);
- D. s = new SortedSet(s);
for (printf("a");printf("b");printf("c")) { break; } What will be the output of the above code snippet?
- ab
- abc
- c
- none of the above
i=3; Printf("%d%d%d",i++,++i,i); What will be output of the code snippet?
- 345
- 456
- 344
- 443