Beruflich Dokumente
Kultur Dokumente
}; f((char *)a); printf(%d, a[1][1]); return 0; } a) *((int*)a + 4 ) = 8 c) (int *)a) [1][1] = 8 d) only a and b
{1,2,3}, {4,5,6}
b) a[1][1] = 8
www.algorithmica.co.in
a) yes, output: 11 12 4 b) yes, output: 11 11 10 c) yes, output: 11 11 11 d) no, error: symbol i is undefined e) no, error: symbol i and next are undefined 6. What would be the output of following program? #include<stdio.h> int main() { char p[ ]="String"; int x=0; if(p=="String") { printf("Pass 1\n"); if(p[sizeof(p)-2]=='g')
www.algorithmica.co.in
} a) Pass 1 Fail 2 b) Pass 1 Pass 2 c) Fail 1 Fail 2 d) Fail 1 Pass 2 e) Pass 1 Fail 1
7. What will be the output of following program? #include <iostream> using namespace std; class baseClass { public: void checkFunction() { cout<<"baseclass"; } }; class derivedClass:public baseClass { public: void checkFunction() { cout<<"derived class"; } }; int main(void) { baseClass *ptr = new derivedClass(); ptr->checkFunction(); return 0; } a) baseclass b) derived class c) Compile time error: cannot assign derived class object's address to a baseclass pointer d) Compile time error: cannot resolve function checkFunction e) none 8. What would be the output of following program? #include <iostream> using namespace std; int m=6; void foo(int *p)
www.algorithmica.co.in
} int main() { int n=5; int *ptr=&n; foo(ptr); cout << m << n << endl; return 0; } a) 6 6 b) 7 5 c) 7 6
d) 6 5
e) 7 7
9. What would be the output of following program? #include <iostream> using namespace std; int main() { int foo = 3; int &bar = foo; bar = 5; cout << foo << << bar << ; foo = 10; cout << foo << << bar << endl; return 0; } a) 5 5 10 10 b) 3 5 10 5 c) 5 5 5 10
d) 3 5 10 10
e) None
10. What would be the output of following program? #include <iostream> using namespace std; class Foo { public: void g() { cout << "Foo::g()"; cout << endl; } } class Bar : public Foo { public: virtual void g() { cout << "Bar::g()"; cout << endl;
www.algorithmica.co.in
c) Foo::g() Foo::g()
d) Bar::g() Foo:g()
e) none
11. Consider the following java code: public class MyClass { private final int UNIQUE_ID = 1729; public static void main(String[] args) { System.out.println (MyId is + UNIQUE_ID); } } Which of the following is true about the above piece of Java code? a. UNIQUE_ID cannot be initialized during declaration. It has to be done inside the constructor. b. Every public class should have a default constructor. c. UNIQUE_ID is not a static member of the class and cannot be referred from main although it is final. d. None of these 12. What is the output of following java program? class MyInteger { private int myInt; public MyInteger(int val) { myInt = val; } public void setMyInt(int val) { myInt = val; } public int getMyInt() { return myInt; } public String toString() { return myInt + ""; } } public class Argument { public void firstAdd(MyInteger int1, MyInteger int2) { int1 = new MyInteger(int1.getMyInt() + int2.getMyInt()); } public void secondAdd(MyInteger int1, MyInteger int2) { int1.setMyInt(int1.getMyInt() + int2.getMyInt());
www.algorithmica.co.in
} a. b. c. d. e.
13. What is the output of following java code snippet? public class javatest { public static void main(String args[]) { String s1 = "Hello", s2 = "Hello"; if(s1 == s2) System.out.println("True"); else System.out.println("False"); s2 = s2.replaceAll("H","K"); s2 = s2.replaceAll("K","H"); if(s1 == s2) System.out.println("True"); else System.out.println("False"); } } a. True True b. False False c. True False d. False True e. None 14. What is the output of following code snippet? public class Foo { int m_a = 0, m_b = 0; public Foo(int a, int b) { m_a = a; m_b = b; }
www.algorithmica.co.in
15. What is the output of following java program? public class test { public static void main(String args[]) { String s1 = Hello; String s2 = Hello; s1.replace(l,k); s2.replace(l,s); System.out.printn( s1 + s2 );
} a. b. c. d. e.
www.algorithmica.co.in
www.algorithmica.co.in
www.algorithmica.co.in
} What is the time complexity of the function f (A, m, m) in terms of Big-Oh? a. m b. m2 c. 2m d. 1 e. m log m
3. Following is the code for Simulating a QUEUE with two STACKS class QUEUE { private stack in,out;
www.algorithmica.co.in
www.algorithmica.co.in
www.algorithmica.co.in
www.algorithmica.co.in
www.algorithmica.co.in
www.algorithmica.co.in
www.algorithmica.co.in
www.algorithmica.co.in