In C, what is the result of declaring a pointer as int *ptr; without initialization?
Question
In C, what is the result of declaring a pointer as int *ptr; without initialization?
Solution
When you declare a pointer in C like this: int *ptr; without initialization, the pointer ptr gets a garbage value, or more specifically, it points to some arbitrary memory location. This can lead to undefined behavior if you try to access or manipulate the memory location that ptr points to without properly initializing it first. It's generally a good practice to initialize a pointer to NULL if you don't have a suitable address to assign it at the time of declaration. This way, you can easily check whether the pointer has been properly initialized or not later in your code.
Similar Questions
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
Comment on the following pointer declaration.int *ptr, p;
What does the expression *ptr++ represent when applied to a pointer ptr in C?
What is the correct syntax to declare a pointer in C++?int &ptr;int ptr*;int *ptr;int ptr&;
In C++, pointer can be initialized with
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.