in Programming in C edited by
2,013 views
4 votes
4 votes

Prior to using a pointer variable it should be

  1. declared.
  2. initialized.
  3. both declared and initialized.
  4. none of these.
in Programming in C edited by
by
2.0k views

4 Comments

The comment above has explained it better. It is even confirmed by Arjun sir.

The first time assigning a value to a pointer variable is initialization. If we reassign a value to that pointer variable again that’s an assignment. We can have a pointer variable that isn’t initialized. But dereferencing an uninitialized pointer is invalid.

This is what I understood.
0
0
But still you said initialisation is not necessary.

Without initialisation, pointer will always point to some invalid memory location. And using (dereferencing) it may result in runtime error.
0
0
Yup, it isn’t. Is anything wrong with it?
0
0

1 Answer

2 votes
2 votes
 int a = 10;
    int *ptr;       //pointer declaration
    ptr = &a;       //pointer initialization

 

or 

 int *ptr = NULL;
    return 0;

answer c is correct

Answer:

Related questions