Friday, 19 August 2016

C & C++ Programming Multiple Choice Questions - Set 24

1.       What will be the output of the following code segment?
main( ) {
char s[10];
strcpy(s, “abc”);
printf(“%d %d”, strlen(s), sizeof(s));
}
(A) 3 10              (B) 3 3
(C) 10 3                         (D) 10 10
Answer: A
Explanation:
strlen(s) give the length of the string, that is 3 and sizeof(s) give the size of array s that is 10.
2.       The protected access specifier is needed only when ................ is needed.
(A) inline function       (B) file
(C) friend function       (D) inheritance
Answer: D
3.       The ................... member variable cannot have an initializer.
(A) static            (B) non-static
(C) auto             (D) register
Answer: B
4.       A structure defines a .................. type.
(A) class                        (B) pointer
(C) arrays          (D) variables
Answer: A
5.       How many times the following code prints the string “hello”.
for(i=1; i<=1000; i++);
printf(“hello”);
(A) 1                   (B) 1000
(C) Zero             (D) Syntax error
Answer: A
Explanation:
The “for” loop is terminated by a semicolon so the next statement is execute that is printing hello.

6.       A generic function is created using the keyword ..................
(A) template                  (B) generic
(C) friend                       (D) class
Answer: A
7.       A generic function is also called as ..............
(A) friend function       (B) template function
(C) virtual function      (D) special function
Answer: B
8.       Find the invalid identifiers from the following:-
(i) nA      (ii) 2nd            (iii) ROLL NO            (iv) case
(A) (i), (ii) and (iv)         (B) (i) and (iii)
(C) (ii), (iii) and (iv)       (D) (ii), (i) and (iii)
Answer: C
Explanation:
Identifier cannot start with a digit; it cannot have a space and case is a keyword.
9.       Which of the following is the proper declaration of a pointer?
(A) int x;             (B) int &x;
(C) ptr x;             (D) int *x;
Answer: D
10.    Which of the following gives the memory address of integer variable a?
(A) *a;                 (B) a;
(C) &a;               (D) address(a);
Answer: C


0 comments:

Post a Comment

UGC NET Computer Science

Computer GK App