#include "stdio.h" int * gPtr; int main() { int * lPtr = NULL; if(gPtr ==…
2024
#include "stdio.h"
int * gPtr;
int main()
{
int * lPtr = NULL;
if(gPtr == lPtr)
{
printf("Equal!");
}
else
{
printf("Not Equal");
}
return 0;
}
Answer: A. It’ll always print Equal. — In C, global variables are initialized to zero by default. Since gPtr is a global pointer, it is initialized to NULL. In main(), lPtr is a local pointer…
- A.
It’ll always print Equal.
- B.
It’ll always print Not Equal.
- C.
Since gPtr isn’t initialized in the program, it’ll print sometimes Equal and at other times Not Equal.
- D.
error
Attempted by 237 students.
Show answer & explanation
Correct answer: A
In C, global variables are initialized to zero by default. Since gPtr is a global pointer, it is initialized to NULL. In main(), lPtr is a local pointer explicitly initialized to NULL. The comparison gPtr == lPtr compares two NULL pointers, which evaluates to true. Therefore, the if condition is satisfied, and "Equal!" is printed.
हिन्दी उत्तर: C में, ग्लोबल वेरिएबल्स को डिफ़ॉल्ट रूप से शून्य से इनिशियलाइज़ किया जाता है। चूँकि gPtr एक ग्लोबल पॉइंटर है, इसलिए यह NULL से इनिशियलाइज़ होता है। main() में, lPtr एक लोकल पॉइंटर है जिसे स्पष्ट रूप से NULL से इनिशियलाइज़ किया गया है। gPtr == lPtr की तुलना दो NULL पॉइंटर्स की होती है, जो ट्रू के रूप में मूल्यांकित होती है। इसलिए, अगर शर्त संतुष्ट होती है, और "Equal!" प्रिंट होता है।