Sie sind auf Seite 1von 6

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

Who will allocate the memory for the statement int i; compiler linker operating system device driver Which of the following statement is true? Dynamically allocated memory will not be released automatically when function returned. Statically allocated memory will not be released automatically when function returned. If constructor is defined as private then it is not possible to invoke it. Memory device driver inserts unused blocks into the free blocks list. In which of the following case copy constructor will not be called? When object initialize When object is passed as a parameter to a function. When temporary object created and returns the value to main function. When object is assignment is taken place When to declare base class destructor virtual? class hierarchy uses dynamic binding

a) b) c) d)

An implementation of a queue Q, using two stacks S1 and S2, is given below: Void insert(Q, x) { Push(S1, x); } Void delete(Q) { If(stack-empty(s2)) then If(stack-empty(S1)) then { Print(Q is empty); Return; } Else while(!(stack-empty(S1))) { X = pop(S1); Push(S2,x); } } Let n insert and m(<=n) delete operations be performed in an arbitary order on an empty queue Q. Let x and y be the number of push and pop operations performed respectively in the process. Which one of the following true for all m and n? n+m<=x<2n and 2m<=y<=n+m n+m<=x<2n and 2m<=y<=2n 2m<=x<2n and 2m<=y<=n+m 2m<=x<2n and 2m<=y<=2n

6) Consider the following C-function in which a[n] and b[m] are two sorted integer arrays and c[n+m] be another integer array. Void xyz(int a[], int b[], int c[]) { Int I, j, k; I=j=k=0; While((i<n) && (j<m)) If(a[i] < b[j]) c[k++] = a[i++];

Else c[k++] = b[j++]; Which of the following condition(s) hold(s) after the termination of the while loop? i) j<m, k=n+j-1 and a[n-1]<b[j] if i=n ii) i<n, k=m+i-1 and b[m-1]<=a[i] if j=m a) only (i) b) only (ii) c) either (i) or (ii) but not both d) both 7) consider the following C-program void foo(int n, int sum) { int k=0, j=0; if(n==0) return; k = n % 10; j = n/10; sum += k; foo(j, sum); printf(%d,k); } Int main() { Int a = 2048, sum = 0; Foo(a, sum); Printf(%d\n,sum); } What does the above program print? a) 8, 4, 0, 2, 14 b) 8, 4, 0, 2, 0 c) 2, 0, 4, 8, 14 d) 2, 0, 4, 8, 0 8) Consider the following C-program: Float foo(float); /* Line 1 */

Int main() { Float fa, fb; //input fa Fb = foo(fa); } Float foo(float a) { Return a; } The above code compiled without any error or warning. If Line 1 is deleted, the above code will show: a) b) c) d) 9) no compile warning or error some compiler-warnings not leading to unintended results some compiler-warnings due to type-mismatch leading to unintended results compiler errors Consider the following C-program int f(int n)

{ static int i=1; if(n>=10) return n; n += i; i += n; f(n); a) b) c) d) 10) } The value returned by f(1) is 16 18 26 34 The output of the following program is: void foo() { int i; char p[20]; char *s = "string"; int len = strlen(s); for(i=0; i<len; i++) p[i] = s[len-i]; printf("%s",p); } gnirts string gnirt no output is printed

a) b) c) d)

#include <iostream.h> #include<conio.h> long countPaths; void findPath(int row, int col) { int next_pos[3][2]; int i; int paths = 0; int found = 0; //std::cout << row << " " << col << '\n'; if(row == 3 && col == 3) { countPaths++; return; } next_pos[0][0] = row+1; next_pos[1][0] = row; next_pos[2][0] = row+1; next_pos[0][1] = col; next_pos[1][1] = col+1; next_pos[2][1] = col+1;

for(i=0; i<3; i++) { if(next_pos[i][0] < 4 && next_pos[i][1] < 4) { printf("(%d,%d)",next_pos[i][0],next_pos[i][1]); findPath(next_pos[i][0],next_pos[i][1]); } } return; } int main() { findPath(0,0); // clrscr(); cout<<"total paths available "<<countPaths<<"\n"; getch(); }

11) There are some men and some lodges for which the following conditions hold true i) Each lodge is represented by exactly 3 men . ii) Each man is associated with exactly 2 lodges. iii) Any pair of lodge has only one man in common. How many men and how many lodges were there? a) 6 b) 8 c) 8 d) 8 men men men men and and and and 4 4 5 6 lodges lodges lodges lodges

12) What will the following program do?


void main() { int i; char a[]="String"; char *p="New String"; char *Temp; Temp=a; //Line number: 7) a=malloc(strlen(p) + 1); strcpy(a,p); //Line number:9// p = malloc(strlen(Temp) + 1); strcpy(p,Temp); printf("(%s, %s)",a,p); free(p); free(a); } //Line number 15// a) Swap contents of p & a and print:(New string, string) b) Generate compilation error in line number 7 c) Generate compilation error in line number 8

d) Generate compilation error in line number 10

13) Find the output for the following C program main() { char *p1=String"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } a) b) c) d) Compilation error Run time error String No output printed

14)

class Sample { public: int *ptr; int p; Sample(int i) { ptr = new int(i); *ptr = I; p = I; } ~Sample() { delete ptr; } void PrintVal() { cout << "The value is " << *ptr + p; } }; void foo(Sample x) { cout << x.p; } int main() { Sample s1= 10; foo(s1); s1.PrintVal(); }
a) Compilaion error

b) Run time error c) Linker error d) 1020 15)

class foo{ public: bool operator==(foo temp); }; bool foo::operator==(foo temp){ if(*this == temp ) { cout<<"The both are same objects\n"; return true; }Else { cout<<"The both are different objects\n"; return false; } } void main(){ foo a1, a2; a1= =a2; }
e) f) g) h) 16) Compilaion error Run time error The both are same objects The both are different objects

Das könnte Ihnen auch gefallen