Filters
Question type

Study Flashcards

Which arithmetic operations can be performed on pointers?


A) All arithmetic operations that are legal in C++
B) Multiplication, division, addition, and subtraction
C) Addition , subtraction , preincrement, and postincrement
D) Only multiplication and addition
E) None of the above

Correct Answer

verifed

verified

The statement int *ptr; means


A) the variable called ptr will store an integer value.
B) the variable called *ptr will store an asterisk and an integer value.
C) ptr is a pointer variable that will store the address of an integer variable.
D) All of the above
E) None of the above

Correct Answer

verifed

verified

A function may return a pointer, but the programmer must ensure that the pointer


A) is pointing to an object that is still valid after the return of the function.
B) has been assigned an address.
C) was received as a parameter by the function.
D) has not previously been returned by another function.
E) None of the above

Correct Answer

verifed

verified

An array name is a pointer constant because the address it represents cannot be changed during run-time.

Correct Answer

verifed

verified

With pointer variables you can access, but you cannot modify, data in other variables.

Correct Answer

verifed

verified

The expression *s->p; is only meaningful if s is a pointer to a structure and p is a pointer that is a member of that structure.

Correct Answer

verifed

verified

The expression s->m has the same meaning as (*s).m.

Correct Answer

verifed

verified

A pointer can be passed as an argument to a function.

Correct Answer

verifed

verified

A statement that displays the address of the variable num1 is


A) cout << num1;.
B) cout << *num1;.
C) cout << &(*num1) ;.
D) cout << &num1;.
E) None of the above

Correct Answer

verifed

verified

Suppose that a function dynamically allocates a block of memory with a local pointer variable p pointing to the allocated block. Suppose further that there are no other pointers referencing that block of memory, and the function returns without doing a delete on p. Then


A) the pointer p becomes a dangling pointer.
B) the compiler will automatically deallocate the memory pointed to by p.
C) the program will suffer from memory leaks.
D) the returning function will throw the bad_alloc exception.
E) None of the above

Correct Answer

verifed

verified

C++ does not perform array bounds checking.

Correct Answer

verifed

verified

If s is a structure variable and p, a pointer, is a member of the structure, the statement cout << *s.p; will


A) output the dereferenced value pointed to by p.
B) result in a compiler error.
C) output the address stored in p.
D) output the value stored in s.
E) None of the above

Correct Answer

verifed

verified

A

To dereference a structure pointer and simultaneously access a member of the structure, the appropriate operator to use is


A) the ampersand, &.
B) an asterisk, *.
C) the structure pointer operator, ->.
D) the dereference operator, <-.
E) None of the above

Correct Answer

verifed

verified

C

The ampersand (&) is used to dereference a pointer variable in C++.

Correct Answer

verifed

verified

False

Which of the following statements correctly deletes a dynamically-allocated array pointed to by p?


A) delete p;
B) p delete[ ];
C) delete [ ] p;
D) delete array p;
E) None of the above

Correct Answer

verifed

verified

A pointer variable may be initialized with


A) any non-zero integer value.
B) the address of an existing variable of the appropriate type.
C) A and B are both True.
D) None of the above

Correct Answer

verifed

verified

A pointer with the value 0 (zero) is called the NULL pointer.

Correct Answer

verifed

verified

Which of the following statements is not valid C++ code?


A) int ptr = &num1;
B) int ptr = int *num1;
C) float num1 = &ptr2;
D) All of the above are valid.
E) All of the above are invalid.

Correct Answer

verifed

verified

The code segment int *ptr; has the same meaning as


A) int ptr;.
B) *int ptr;.
C) int ptr*;.
D) int* ptr;.
E) None of the above

Correct Answer

verifed

verified

A reason for passing a pointer to a function is


A) to avoid the overhead of copying large data structures.
B) to allow the called function to modify a variable accessible to the calling function.
C) to allow easy access to data in the function that is being called.
D) A and B are both True.
E) None of the above

Correct Answer

verifed

verified

Showing 1 - 20 of 62

Related Exams

Show Answer