Computer Science Study Materials for Competitive Exams

Sample Questions, Previous Year Solved Papers, Study Materials For Competitive Examinations Like UGC NET, SET And GATE Computer Science.

Wednesday, 9 August 2017

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

1.       What will be the output of following program?
#include<iostream.h>
void main()
{
float x;
x=(float)9/2;
cout<<x;
}
(A) 4.5
(B) 4.0
(C) 4
(D) 5
Answer: A
2.       A white space is :
(A) blank space
(B) new line
(C) tab
(D) all of the above
Answer: D
3.       The following can be declared as friend in a class
(A) an object
(B) a class
(C) a public data member
(D) a private data member
Answer: B
4.       What would be the output of the following?
#include<iostream.h>
void main()
{
char *ptr=“abcd”
char ch;
ch = ++*ptr++;
cout<<ch;
}
(A) a
(B) b
(C) c
(D) d
Answer: B
5.       A copy constructor takes
(A) no argument
(B) one argument
(C) two arguments
(D) arbitrary no. of arguments
Answer: B

6.       Overloading a postfix increment operator by means of a member function takes
(A) no argument
(B) one argument
(C) two arguments
(D) three arguments
Answer: A
7.       Which of the following ways are legal to access a class data member using this pointer?
(A) this.x
(B) *this.x
(C) *(this.x)
(D) (*this).x
Answer: D
8.       If a=8 and b=15 then the statement
x= (a>b) ? a:b;
(A) assigns a value 8 to x
(B) gives an error message
(C) assigns a value 15 to x
(D) assigns a value 7 to x
Answer: C
9.       What is the output of the following code
int n=0, m;
for (m=1; m<=n+1; m++)
printf(“%d”, m);
(A) 2
(B) 1
(C) 0
(D) 6
Answer: B
10.    In the following code fragment
int x, y = 2, z, a;
x=(y*=2) + (z=a=y);
printf (‘%d’,x);
(A) prints 8
(B) prints 6
(C) prints 6 or 8 depending on the compiler
(D) is syntactically wrong
Answer: A
Explanation:
It will print 8 because x=(y*=2)+(z=a=y)=4+4=8.

Pages  49   50   51   52   53   54 

No comments:

Post a Comment