Prior to using a pointer variable it should beQuestion 2Answera. Declaredb.None of thesec. Both declared and initalizedd. Initialized
Question
Prior to using a pointer variable it should be
- a. Declared
- b. None of these
- c. Both declared and initialized
- d. Initialized
Solution
The correct answer is c. Both declared and initialized.
Here's why:
Step 1: Declaration of a pointer Before you can use a pointer, you must declare it. Declaration of a pointer basically involves telling the compiler where we want to store the address. This is done using the unary operator (*) that comes after a data type.
For example, int *p;
Here, 'p' is a pointer to an integer.
Step 2: Initialization of a pointer After declaration, a pointer should be initialized to any variable or any address. If not done, it points to some random memory location that can cause undefined behavior.
For example, int x = 10; int *p; p = &x;
Here, 'p' is initialized to the address of 'x'. So, it is now pointing to 'x'.
Therefore, before using a pointer variable, it should be both declared and initialized.
Similar Questions
Prior to using a pointer variable it should beQuestion 2Answera. Declaredb.None of thesec. Both declared and initalizedd. Initialized
Select the correct answerC functions parameters are always by default:OptionsPass by referencePass by valuePass by pointerAll given options are correct
Which of these is a correct way to initialize a pointer in C?Marks : 1Negative Marks : 0Answer hereint ptr = 0int *ptr = 0int ptr = NULLint *ptr = NULL
The operator used to get value at address stored in a pointer variable isa.*b.&c.&&d.||
In C a pointer variable to an integer can be created by the decalarationa.int p*;b.int *p;c.int +p;d.int $p;
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.