Sts3005 Mcq's
Sts3005 Mcq's
Sts3005 Mcq's
MCQ’s
Q1. Find the Output:
#include<iostream>
using namespace std;
class A
{
public:
A() { cout << "A's constructor called "; }
};
class B
{
public:
B() { cout << "B's constructor called "; }
};
class C: public B, public A
{
public:
C() { cout << "C's constructor called "; }
};
int main()
{
C obj;
return 0;
}
Q2. #include<iostream>
using namespace std;
class Base {
public:
virtual int fun(int x) {
cout<<"Base";
}
};
class Derived: public Base {
private:
int fun(int x) {
cout<<"Derived";
}
};
int main()
{
Derived d;
d.fun(1);
return 0;
}
Q3. #include<iostream>
using namespace std;
class Base
{
public:
int fun()
{
cout<<"Base::fun() called";
}
int fun(int i)
{
cout<<"Base::fun(int i) called";
}
};
class Derived: public Base
{
public:
int fun()
{
cout<<"Derived::fun() called";
} };
int main()
{
Derived d;
d.fun(5);
return 0;
}
Q4.#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int *arr[ ] = {&a, &b, &c};
cout << arr[1];
return 0;
}
Q5. #include <iostream>
using namespace std;
int main()
{
int a = 9;
int & aref = a;
a++;
cout << "The value of a is " << aref;
return 0;
}
Q6.
#include<stdio.h>
union u{
int i;
char c;
double d;
};
int main()
{
union u u1;
printf("%d",sizeof(u1));
return 0;
}
Q7. #include<stdio.h>
int main()
{
float f=0.1;
if(f==0.1)
printf("YES");
else
printf("NO");
return 0;
}
Q8.
#include<stdio.h>
int main()
{
int n,ch;
for(n=7;n!=0;n--)
printf("n=%d\n",n--);
ch=getchar();
return 0;
}
Q9. Which of the below statements is true?
a) A static function can only return a static
variable
b) A static variable can be declared only inside a
static function
c) Variables passed to a static function should
also be static
d) None of the above options
Q10. int main(int argc, char **argv)
In the above definition of main function, the variable
argv denotes:
a) An array of character pointers each pointing to the
command line parameters.
b) An array of character pointers, the first array item
pointing to the program name and the remaining
pointing to the command line parameters.
c) A pointer to character that points to command line
parameters.
d) A pointer to pointer that points to the memory
location where the program has been loaded into the
memory.
Q11. #include<stdio.h>
#define MAX 20
char *fn(char[]);
int main(void)
{
char str[MAX], *rev;
printf("Enter a word of size not more than 15 characters: ");
scanf("%s", str);
rev=fn(str);
printf("\n%s",rev);
return 0;
}
char* fn(char str[])
{
static int i=0;
static char r[MAX];
if(*str)
{
fn(str+1);
r[i++]=*str;
}
return r;
}
What is the output of the given program if user gives HELLO as input?
Q12. What is dangling pointer?
a) Points to garbage value
b) Points to function
c) Both A and B
d) None of the above options
Q13. What does a default header file contain?
a) Prototypes
b) Declarations
c) Implementations
d) All of the above
Q14. Consider the following code:
function modify(w,u)
{
w=w+2
u=u-3
return (w - u)
}
function calculate( )
{
integer a = 10, b = 20, c
c = modify(a, b);
print a
print space
print b
}
Assume that a was passed by value and b was passed by reference. What will be
the output of the program on executing function calculate( ) ?
Op 1: 12 17
Op 2: 10 17
Op 3: 12 20
Op 4: 10 20
Q15. Which of these is not a data type?
Op 1: integer
Op 2: character
Op 3: boolean
Op 4: array
Q16. Consider the following code:
function modify(y,z)
{
y = y + 1;
z = z + 1;
return y - z
}
function calculate( ) {
integer a = 5, b = 10, c= modify(a, b);
print a
print space
print c
}
Assume that a and b were passed by value. What will be the output on
executing function calculate( )?
Op 1: 11 -5
Op 2: 10 -5
Op 3: 6 -5
Op 4: 5 -5
Q17. Consider following given code and predict its output.
main()
{
int num[ ] = {1,4,8,12,16};
int *a,*b;
int i;
a=num;
b=num+2;
i=*a+1;
printf("%d,%d,%d\n"i,*a,*b);
}
A. 2,1,8
B. 4,1,8
C. 4,4,8
D. 2,4,8
Q18. What is the output of the following code? The
compiler saves the first integer at the memory location
4165 and the rest at consecutive memory spaces in
order of declaration. Integer is one byte long.
integer a, b
integer pointer c, d, a = 30
c = &a
b = *c
a = a + 10
print b
Op 1: 30
Op 2: 4165
Op 3: 40
Op 4: 4166
Q19. Shrishti writes the code for a function that
computes the factorial of the inputted number n.
function factorial(n)
{
if(n equals 1)
return 1
else
-- MISSING STATEMENT --
}
Fill in the missing statement.
Op 1: return factorial(n-1)
Op 2: return n*factorial(n)
Op 3: return n*(n-1)
Op 4: return n*factorial(n-1)
Q20. Return type of rand() function is:
A) short B) int
C) char D) float
Q21. include<iostream>
using namespace std;
namespace first
{
intvar = 5;
}
namespace second
{
doublevar = 3.1416;
}
int main ()
{
int a;
a = first::var + second::var;
cout<< a;
return 0;
}
A) 8.31416 B) 8
C) 9 D) Compile time error
Q22. Which of following is true?
A) private and protected members of a class cannot
be accessed from outside
B) private and protected member can be accessed
anywhere
C) both a & b
D) None of the mentioned
Q23.#include<stdio.h>
union student
{
int y[34];//Consider int as 2 byte
char var2[7];//Consider char as 1 byte
char arr[8];
char ch[5];
};
int main()
{
union student st;
printf("%d", sizeof(union student));
return 0;
}
A) 126 B) 136
C) 146 D) 142
Q24. #include<iostream>
using namespace std;
int main()
{
enum channel {star, sony, zee};
enum symbol {hash, star};
int i = 0;
for (i = star; i<= zee; i++) {
printf("%d ", i);
}
return 0;
}
A) 012 B) 123
C) error D) 0123
Q25. What is the purpose of ftell?
(a) To get the current file name
(b) To get the current file status
(c) To get the current file attribution
(d) To get the current file position
Q26. Which of the following statements is true about
C language?
(a)char *i = 0; and char *i = null; mean the same.
(b)(void*) 0 is different from a null pointer.
(c)calloc () can be used only for character pointer
allocation.
(d)null pointer is another name for un initialized
pointer.
Q27. Assume int is 4 bytes, char is 1 byte and float is 4
bytes. Also, assume that pointer size is 4 bytes (i.e.
typical case)
char *p;
int *q;
float *r;
sizeof(p);
sizeof(q);
sizeof(r);
(a) 4 4 4 (b) 1 4 4 (c) 1 4 8 (d) None of these
Q28. What the below statement will print if a=5?
printf(“%d %d”, a, !a++);
(a) 50 (b) 60 (c) 51 (d) 61
Q29. What is the return type of malloc() or calloc()?
(a) void* (b) Pointer of allocated memory type
(c) void** (d) int*
Q30. What is the output?
#include<stdio.h>
int main()
{
int i, j, *ptr, *ptr1;
i = 10;
j = 10;
ptr = &i;
ptr1 = &j;
if(ptr == ptr1)
{
printf(“True”);
}
else
{
printf(“False”);
}
}
(a) True (b) False (c) Compiler Error (d) No output
Q31) What is the output of the following program?
#inlude<stdio.h>
void main(){
int a;
a=1;
while(a<=10){
printf(“%d “,a);
if(a>3)
break;
a++;
}
Printf(“%d”,a+10);
}
(a) 1 2 3 4 10 (b) 1 2 3 4 14 (c) 1 2 3 13 (d) 1 2 3 14
Q32. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int y = 5;
int z = y + (y = 10);
printf(“%d\n”, z);
}
(a) 4 (b) 20 (c) Either 12 or 20 (d) 12
Q33. #include<stdio.h>
main()
{
printf(“\n Main Called Again”);
main();
}
(a) Error (b) Infinite times
(c) No output (d) None of these
Q34. The number of tokens in the following C
statement in printf(“j = %d, &j = %x”, j, &j);
(a) 1 (b) 4 (c) 5 (d) 10
Q35. What is the output of the following program?
#include<stdio.h>
void main()
{
printf(“1”);
goto XYZ;
printf(“2”);
XYZ:
printf(“3”);
}
(a) 3 (b) 13 (c) 123 (d) 12
Q36. What is the output of the following program?
#include<stdio.h>
void main()
{
int a;
float f;
a=13/2;
f=13/2;
printf(“%d %f”,a,f);
}
(a) 6 6.500000 (b) 6 6.5
(c) 6 6.000000 (d) None of these
Q37. #include<iostream>
int main()
{
std::cout<< "\"smart\"";
return 0;
}
(a)smart (b)\”smart\”
(c)Syntax error (d)”smart”
Q38. #include<iostream.h>
int val = 0;
class Cse
{
public:
Cse() { cout<< ++val; }
~Cse() { cout<<val--; }
};
int main()
{
Cse objBix1, objBix2, objBix3;
{
Cse objBix4;
}
return 0;
}
(a) 1234 (b) 4321 (c) 12344321 (d) 43211234
Q39.
#include<iostream.h>
class Smart
{
static int x;
public:
static void SetData(int xx)
{x = xx; }
static void Display()
{ cout<< x ; }
};
int Smart::x = 0;
int main()
{
Smart::SetData(44);
Smart::Display();
(a) The program will print the output 0.
return 0; (b) The program will print the output 44.
} (c) The program will print the output Garbage value.
(d) The program will report compile time error.
Q40. #include<iostream>
int main()
{
int x = 10, y = 20;
int *ptr = &x;
int& ref = y;
*ptr++;
ref++;
cout<< x <<" "<< y;
return 0;
}
(a)10 20 (b)10 21 (c)11 20 (d)11 21
All the best