Quick Test 14: Pointers

1. How to declare a pointer to an int?

int *a; 
int a*;
int &a;
int a&;

2. How to attribute the address of variable x to pointer p?

Depends on the type of x.
p = *x;
p = &x;
p = ^x;

3. Assume  b is a variable of type "pointer to int";
How to put a value of 0 in b?

4. What happens if we forget to initialize a pointer?
 

The result will be 0.
The compiler will warn us.
The program will crash.
The pointer is automatically initialized.

5. What is wrong in the following code?

  double *p;
  int i;
  p = &i;
  *p = 10.0;

We mixed * with &.
*p = 10.0; will overwrite other variables or code.
p = &i; will generate an error.
Nothing is wrong here.

6.  What are the advantages of pointers

1: 
2: