Sunday, July 21, 2013

C MCQ Test - 3

Que.1. If the size of integer is 4bytes, What will be the output of the program?

#include<stdio.h>

int main()

{

int arr[] = {12, 13,14,15,16};

printf("%d, %d, %d",sizeof (arr),sizeof(*arr),sizeof(arr[0]));

return 0;

}



A:        16, 2, 2

B:         20, 2, 2

C:         j=s;

D:        *j=s;



Right Answer: B



Que.2. Are the following two statement same?



1.a <= 20 ? (b = 30): (c = 30);

2.(a <=20) ? b : (c = 30);



A:        Yes

B:         No

C:         True

D:        False



Right Answer: B





Que.4. What will be the output of the program ?

#include<stdio.h>

int main()

{

int i;

char a[] ="";

if(printf("%s", a))

printf("The string is empty");

else

printf("The string is not empty");

return 0 ;

}



A:        No output

B:         0

C:         1022 Hello2

D:        Hello1 1022



Right Answer: B



Que.5. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=4, j=-1, k=0, w, x, y, z;

w = i || j || k;

x = i && j && k;

y = i || j &&k;

z = i && j || k;

printf("%d, %d, %d, %d", w, x, y, z);

return 0;

}



A:        1, 1, 1, 1

B:         1, 1, 0, 1

C:         1, 0, 0, 1

D:        1, 0, 1, 1



Right Answer: D



Que.6. Can I increase the size of dynamically allocated array?



A:        No

B:         cmp - is a pointer to an void function type.

C:         cmp - is a void type pointer function.

D:        cmp - is a function that return a void pointer.



Right Answer: A



Que.7. Will the following program print the message infinite number of times?

#include<stdio.h>

#define INFINITELOOP while(1)

int main()

{

INFINITELOOP

printf("HelloWorld" );

return 0;

}



A:        Yes

B:         No

C:         10

D:        20



Right Answer: A



Que.8. In the following program add a statement in the function

fact()such that the factorial gets stored in j



#include<stdio.h>

void fact( int*);

int main()

{

int i= 5;

fact(&i);

printf("%d", i);

return 0;

}

void fact(int *j)

{

static int s=1;

if(*j!=0)

{

s = s**j;

*j = *j-1;

fact(j);

/* Add a statement here */

}

}



A:        *j=&s;

B:         &j=s;

C:         65486, 65488

D:        65486, 65486



Right Answer: B



Que.9. What will be the output of the program ?

#include<stdio.h>

int *check(static int,static int);

int main()

{

int *c;

c = check(10,20);

printf("%d", c);

return 0;

}

int *check( static int i, static int j)

{

int *p, *q;

p = &i;

q = &j;

if(i >= 45)

return (p);

else

return (q);

}



A:        Error: Non portable pointer conversion

B:         Error: cannot use static for function parameters

C:         10, 2, 4

D:        20, 4, 4



Right Answer: D



Que.10. What will be the output of the program if the array begins at address 65486?

#include<stdio.h>

int main()

{

int arr[] = {12,14,15,23,45};

printf("%u, %u", arr, &arr);

return 0 ;

}



A:        65486, 65490

B:         65486, 65487

C:         The string is empty

D:        The string is not empty



Right Answer: B



Que.11. What will be the output of the program?

#include<stdio.h>

typedef struct error {

int warning, err, exception;

} ERROR;

int main()

{

ERROR e;

e.err=1;

printf("%d", e.err);

return 0;

}



A:        strnchar()

B:         strchar()

C:         strrchar()

D:        strrchr()



Right Answer: B





Que.13. If the different command line arguments are supplied at different times would the output of the following program change?

#include<stdio.h>

int main(int argc, char **argv)

{

printf("%d", argv[argc]);

return 0;

}



A:        10

B:         11

C:         No output

D:        Error: ++needs a value



Right Answer: B



Que.14. What will be the output of the program ?

#include<stdio.h>

int main()

{

char *str;

str = "%d";

str++;

str++;

printf(str- 2,300);

return 0;

}



A:        Yes

B:         No

C:         65474, 65476

D:        65480, 65496



Right Answer: D



Que.16. How many times "HelloWorld" is get printed?

#include<stdio.h>

int main()

{

int x;

for(x=-1; x<= 10; x++)

{

if(x <5)

continue;

else

break;

printf("HelloWorld");

}

return 0;

}



A:        Infinite times

B:         11 times

C:         0 times

D:        10 times



Right Answer: C



Que.17. Macros have a local scope.



A:        No output

B:         30

C:         3

D:        300



Right Answer: B



Que.18. What will be the output of the program?

#include<stdio.h>

int addmult(int ii,int jj)

{

int kk, ll;

kk = ii + jj;

ll = ii * jj;

return (kk, ll);

}

int main()

{

int i=3, j=4, k, l;

k = addmult(i, j);

l = addmult(i, j);

printf("%d, %d", k, l);

return 0;

}



A:        12, 12

B:         7, 7

C:         7, 12

D:        12, 7



Right Answer: A

C++ MCQ Test - 3



Que.1. Which type of class has only one unique value for all the objects of that same class?

A:            this
B:            Friend
C:            Static
D:            both a and b

Right Answer: C

Que.2. What is a constructor?

A:            A class automatically called whenever a new object of this class is created.
B:            A class automatically called whenever a new object of this class is destroyed.
C:            A function automatically called whenever a new object of this class is created.
D:            A function automatically called whenever a new object of this class is destroyed.

Right Answer: C

Que.3. Under which of the following circumstances, synchronization takes place?

A:            When the file is closed
B:            When the buffer is empty
C:            Explicitly, with manipulators
D:            both a and c

Right Answer: D

Que.4. Which of the following functions below can be used Allocate space for array in memory?

A:            calloc()
B:            malloc()
C:            Realloc()
D:            both a and b

Right Answer: A

Que.5. C++ provides facility to specify that the compiler should match function calls with the correct definition at the run time. This process is called as

A:            Static binding
B:            Dynamic Binding

Right Answer: B

Que.6. By default, all members of a class have ___________ access for all its members

A:            Public
B:            Protected
C:            No access
D:            private

Right Answer: D

Que.7. How would you read the expression x.y as?

A:            member y of object pointed by x
B:            member y of object x
C:            member x of object y
D:            All choices are correct.

Right Answer: B

Que.8. Under what conditions a destructor destroys an object?

A:            Scope of existence has finished
B:            Object dynamically assigned and it is released using the operator delete.
C:            Program terminated.
D:            Both a and b.

Right Answer: D

Que.9. Which operator is used to define a member of a class from outside the class definition itself?

A:            ::
B:            :
C:            >>
D:            <<

Right Answer: A

Que.10. if no constructor is declared, the compiler assumes the class to have a default constructor with no arguments

A:            True
B:            False

Right Answer: A

Que.11. ios::ate is used for

A:            Set the initial position at the end of the file.
B:            Set the initial position at the start of the file.
C:            Set the last position at the end of the file.
D:            Set the last position at the start of the file.

Right Answer: A

Que.12. What defines a general set of operations that will be applied to various types of data?

A:            Template class
B:            Function template
C:            Class template
D:            Both a and c above

Right Answer: B

Que.13. What is deep copy?

A:            A deep copy creates a copy of the dynamically allocated objects too.
B:            A deep copy just copies the values of the data as they are.
C:            A deep copy creates a copy of the statically allocated objects too
D:            Both b and c above

Right Answer: A

Que.14. How do we check if the file has reached its end?

A:            Use if_file_end()
B:            use end_of_file()
C:            use eof()
D:            both a and c

Right Answer: C

Que.15. There is nothing like a virtual constructor of a class.

A:            False
B:            True

Right Answer: B

Que.16. What happens when a pointer is deleted twice?

A:            It can abort the program
B:            It can cause a failure
C:            It can cause an error
D:            It can cause a trap

Right Answer: D

Que.17. What is the Difference between struct and class in terms of Access Modifier?

A:            By default all the struct members are private while by default class members are public.
B:            By default all the struct members are protected while by default class members are private.
C:            By default all the struct members are public while by default class members are private.
D:            By default all the struct members are public while by default class members are protected.

Right Answer: C

Que.18. Vtables

A:            creates a static table per class
B:            creates a static table per object
C:            creates a dynamic table per class
D:            creates a dynamic table per object

Right Answer: A

Que.19. Which of the following library function below by default aborts the program?

A:            Terminate()
B:            end()
C:            Abort()
D:            exit()

Right Answer: A

Que.20. What is the output of the following code snippet?
class test {
public:
static int n;
test () { n++; };
~test () { n--; };
};
int test::n=0;
int main () {
test a;
test b[5];
test * c = new test;
cout << a.n << endl;
delete c;
cout << test::n << endl;
return 0;
}

A:            7 6
B:            6 7
C:            5 6
D:            6 5


Right Answer: A