Knowee
Questions
Features
Study Tools

lect the correct answerWhich of the following is a valid declaration of a pointer to a constant integer in C?Optionsconst int *ptr;const int const *ptr;int *const ptr;int const *const ptr;

Question

lect the correct answerWhich of the following is a valid declaration of a pointer to a constant integer in C?Optionsconst int *ptr;const int const *ptr;int *const ptr;int const *const ptr;

🧐 Not the exact question you are looking for?Go ask a question

Solution

The valid declarations of a pointer to a constant integer in C are:

  1. const int *ptr;
  2. int const *ptr;

These two declarations mean that the integer pointed by the pointer is constant and cannot be changed through this pointer.

The other two options:

  1. int *const ptr;
  2. int const *const ptr;

The first one means the pointer itself is constant and cannot point to another integer. The second one means both the integer pointed by the pointer and the pointer itself are constant.

This problem has been solved

Similar Questions

Select the correct answerWhich of the following is the correct way to declare a pointer to an integer in C?Optionsint *ptr;integer *ptr;ptr *int;point int *ptr;

Comment on the following pointer declaration.int *ptr, p;

Comment on the following pointer declaration.int *ptr, p; ptr is a pointer to integer, p is notptr and p, both are pointers to integerptr is a pointer to integer, p may or may not beptr and p both are not pointers to integer

Select the correct answerWhich of the following is a valid way to initialize a constant in C?Optionsint const x = 5;const int x = 5;constant x = 5;int x = const 5;

What is the correct syntax to declare a pointer in C++?int &ptr;int ptr*;int *ptr;int ptr&;

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.