Question: Multiple Answer Question Given the following declarations: struct House { double price; int rooms; }; House *ptr = new House; which of the following is
Multiple Answer Question
Given the following declarations:
struct House
{
double price;
int rooms;
};
House *ptr = new House;
which of the following is (is) valid?
| (a). *ptr.rooms = 5; | ||
| (b) ptr->price = 200000; | ||
| (c) (*ptr)->price = 200000; | ||
| (d) ptr.rooms = 5; | ||
| (e). (*ptr).room = 5; |
2.
Consider the following program:
struct A {
int a1;
double a2;
};
void change(char *ar, A aa)
{
strcpy(ar, HELLO);
aa.a1=10;
aa.a2=3.14;
}
int main()
{
A aa = {3, 2.5};
char ar[10] = " ";
change(ar, aa);
cout << aa.a1 << ' ' << aa.a2 << ' ' << aa.a3 << ar;
return 0;
}
what is the output?
| (a) 3 2.5 C++ | ||
| (b) 3 2.5 Hello | ||
| (c) 10 3.14 C++ | ||
| (d) 10 3.14 Hello | ||
| (e) None of above |
3.
Assuming that ar is an array and ptr is a pointer to that array, which expression refers to the address of the 3rd element of the array?
| (a) *(ptr + 2) | ||
| (b) ptr[2] | ||
| (c) ptr+2 | ||
| (d) *(ar+2) | ||
| (e) None of above |
4.
Which of the following is the correct output of the following statements:
int sum = 5, x = 8, *ptr= &x;
sum += (*ptr)++;
cout << sum << " " << x << endl;
| (a) 14 8 | ||
| (b) 13 9 | ||
| (c) 14 9 | ||
| (d) 13 8 | ||
| (e) Compilation error |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
