Purchase Solution

C++ Questions

Not what you're looking for?

Ask Custom Question

1.
Consider

int a, b;

int *prt; //A pointer
int **prtPrt //A pointer to a pointer

ptr = &a;
prtPtr = &ptr;

a. Is this code legal?
b. What are the values of *ptr and **ptrPtr?
c. Using no other objects besides those already declared, how can you alter ptrPtr so that is points to a pointer to b without directly touching ptr?
d. Is the following statement legal?

2.
a. ls *&x always equal to x? If not, give an example
b. ls &*x always equal to x? Uf not, give an example

3.
For the declarations
int a = 5;
int *ptr - &a;

what are the values of the following?
a. ptr
b. *ptr
c. ptr == a
d. ptr == &a
e. &ptr
f. *a
g. *&a
h. **&ptr

4
Give the typr of each identifier declared here and the types of the expressions. Is any expression illegal?

a. struct X { inta; S *b; };
b. S z;
c. S *x;
d. x->a
e. x->b
f. z.b
g. z.a
h. *z.a
j. (*z).a
k. x->b-z.b
l. &z
m. &x

5
Is the following code legal? Why or why not?

int a = a;
const in & b = a;

6
What is worng with omitting a space in *x/*y?

Purchase this Solution

Solution Summary

C++ questions are answered.

Solution Preview

1. This should loook like this (after fixing syntax prob;lems in names):

int a, b;

int *ptr; //A pointer
int **ptrPtr; //A pointer to a pointer

ptr = &a;
ptrPtr = &ptr;

a. Is this code legal?
- Yes, this code is legal.

b. What are the values of *ptr and **ptrPtr?
The value of *ptr is equal to a. The value of **ptrPtr is also equal to a.

c. Using no other objects besides those already declared, how can you alter ptrPtr so that is points to a pointer to b without directly touching ptr?

*ptrPtr = &b ;

d. Is the following statement legal?
??? (nothing is shown)

2.
a. ls *&x always equal ...

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

This quiz tests a student's knowledge about C++ operators.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Networking Questions

This quiz consists of some basic networking questions.

Javscript Basics

Quiz on basics of javascript programming language.