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
Question
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
Solution
The correct way to initialize a pointer in C is:
int *ptr = NULL;
Here's why:
- int ptr = 0: This is incorrect because it's declaring an integer, not a pointer.
- int *ptr = 0: This is technically correct, but it's not the best practice. In C, NULL is often used for pointers, not 0.
- int ptr = NULL: This is incorrect because it's declaring an integer, not a pointer.
- int *ptr = NULL: This is the correct way to initialize a pointer in C. It declares a pointer and initializes it to NULL.
Similar Questions
What is the correct syntax for declaring a pointer variable?Marks : 1Negative Marks : 0Answer hereint *ptr;pointer int *ptr;*int ptr;None of the mentioned options
How do you initialize a pointer to the address of a variable 'x' ?Marks : 1Negative Marks : 0Answer hereint *ptr = x;int *ptr = &x;*int ptr;int *ptr = *x;
Multi Choice Type QuestionWhat does a null pointer indicate in C?Marks : 1Negative Marks : 0Answer hereA pointer that points to a constant valueAn uninitialized pointerA pointer with a value of zero (NULL)None of the mentioned options
In C, what is the result of declaring a pointer as int *ptr; without initialization?Marks : 1Negative Marks : 0Answer hereThe value of the variableptr points to a specific known memory locationptr contains a garbage value as its addressptr points to the memory location 0
How is a null pointer represented in C?Marks : 1Negative Marks : 0Answer hereNULL0-11
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.