208k views
5 votes
Given the declaration: char a[] = "Hello"; char *p = a, *q; what operations are valid syntactically? Select all that apply. Group of answer choices q = &&a[0]; q = &&a; *q = *(&a[0]); q = &(*p);

1 Answer

1 vote

Answer:

The valid operations are:

*q = *(&a[0]); and q = &(*p);

Step-by-step explanation:

Given

The above declarations

Required

The valid operations

*q = *(&a[0]); and q = &(*p); are valid assignment operations.

However, q = &&a[0]; q = &&a; are invalid because:

The assignment operations intend to implicitly cast the char array a to pointer q. C++ does not allow such operation.

Hence, *q = *(&a[0]); and q = &(*p); are valid

Another way to know the valid operations is to run the program and look out for the syntax errors thrown by the C++ compiler

User Airboss
by
3.4k points