0% found this document useful (0 votes)
23 views

Questions On C++

The "diamond problem" in multiple inheritance occurs when a derived class inherits from two base classes that inherit from a common base class, forming a diamond shape in the inheritance graph. This can cause ambiguity in the derived class as it would inherit the same attribute or method from both base classes. The statement "int (*fp)(char*)" declares fp as a pointer to a function that takes a char* argument and returns an int. The operator used for dereferencing or indirection is the asterisk (*) operator. In the code "string* x, y;", x is declared as a pointer to a string, while y is declared as a string, not a pointer. A valid state

Uploaded by

saurabh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Questions On C++

The "diamond problem" in multiple inheritance occurs when a derived class inherits from two base classes that inherit from a common base class, forming a diamond shape in the inheritance graph. This can cause ambiguity in the derived class as it would inherit the same attribute or method from both base classes. The statement "int (*fp)(char*)" declares fp as a pointer to a function that takes a char* argument and returns an int. The operator used for dereferencing or indirection is the asterisk (*) operator. In the code "string* x, y;", x is declared as a pointer to a string, while y is declared as a string, not a pointer. A valid state

Uploaded by

saurabh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1) C++ supports multiple inheritance.

What is the diamond problem that can


occur with multiple inheritance? Give an example.
2) What does the following statement mean?
int (*fp)(char*)
a) pointer to a pointer
b) pointer to an array of chars
c) pointer to function taking a char* argument and returns an int
d) function taking a char* argument and returning a pointer to int
3) The operator used for dereferencing or indirection is ____
a) *
b) &
c) ->
d) >>
4) Choose the right option
string* x, y;
a) x is a pointer to a string, y is a string
b) y is a pointer to a string, x is a string
c) both x and y are pointer to string types
d) none of the mentioned
5) Which one of the following is not a possible state for a pointer.
a) hold the address of the specific object
b) point one past the end of an object
c) zero
d) point to a byte
6) What will happen in this code?
int a = 100, b = 200;
int *p = &a, *q = &b;
p = q;
a) b is assigned to a
b) p now points to b
c) a is assigned to b
d) q now points to a
7) What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int *arr[ ] = {&a, &b, &c};
cout << arr[1];
return 0;
}

a)5
b)10
c)15
d) it will return some random number
8) The correct statement for a function that takes pointer to a float, a pointer to a
pointer to a char and returns a pointer to a pointer to a integer is
a)int **fun(float**, char**)
b) int *fun(float*, char*)
c) int ***fun(float*, char**)
d) int ***fun(*float, **char)
9) What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
char arr[20];
int i;
for(i = 0; i < 10; i++)
*(arr + i) = 65 + i;
*(arr + i) = '\0';
cout << arr;
return(0);
}
a) ABCDEFGHIJ
b) AAAAAAAAAA
c) JJJJJJJJ
d) none of the mentioned
10) What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
char *ptr;
char Str[] = "abcdefg";
ptr = Str;
ptr += 5;
cout << ptr;
return 0;
}

a) fg
b) cdef
c) defg
d) abcd

You might also like