Which of the following statements creates and initializes a pointer named salesPtr?

[amp_mcq option1=”salesPtr = NULL;” option2=”*salesPtr = “”;” option3=”float &salesPtr = NULL;” option4=”float *salesPtr = “”; E. float *salesPtr = NULL;” correct=”option1″]

The correct answer is E.

A pointer is a variable that stores the address of another variable. The statement salesPtr = NULL creates a pointer named salesPtr and initializes it to the null pointer constant, which is a pointer that does not point to any object. The statement *salesPtr = "" assigns the empty string to the object pointed to by salesPtr, but salesPtr is not initialized, so this statement will cause an error. The statement float &salesPtr = NULL creates a reference named salesPtr that refers to the null pointer constant. This is not a valid way to create a pointer, so this statement will also cause an error. The statement float *salesPtr = "" creates a pointer named salesPtr and initializes it to the address of the empty string. This is a valid way to create a pointer, but it is not a good way to initialize a pointer to a variable of type float. The statement float *salesPtr = NULL creates a pointer named salesPtr and initializes it to the null pointer constant. This is a valid way to create and initialize a pointer.

In conclusion, the correct answer is E.