1 1 vote #include "stdio.h" int * gPtr; int main() { int * lPtr = NULL; if(gPtr == lPtr) { printf("Equal!"); } else { printf("Not Equal"); } return 0; } what will be the outpout : A.> it will always print equal B> it will always print Not equal C>Since gPtr isn’t initialized in the program, it’ll print sometimes Equal and at other times Not Equal. Programming in C + – bharti 2.4k views answer comment Share Follow Print See all 11 Comments 11 11 Comments reply Rishabh Gupta 2 commented Aug 23, 2017 reply Follow flag (C)? 0 0 replyShare saxena0612 commented Aug 23, 2017 reply Follow flag I think global pointers are always initialized to null. 0 0 replyShare bharti commented Aug 23, 2017 reply Follow flag @saxena0612 that is true, but how will the comparison be done . *something =a, that means if we print or compare something then that will give address of "a". here lptr = null so how is gonna be compared . :( 0 0 replyShare bharti commented Aug 23, 2017 reply Follow flag nope , answer is "a" 0 0 replyShare bharti commented Aug 23, 2017 reply Follow flag My confusion is : Global pointer *gPtr will take some space in Static area, where *Lptr scope is within the main function so it will take some space in stack area of memory. now when we write pointer variable name only that refers to pointing address . so how can the if condition be true , where the pointing address is not the same ?? 0 0 replyShare saxena0612 commented Aug 23, 2017 reply Follow flag @bharti let me clear you confusion basically when you point pointer to NULL then it means that it is pointing to the memory address 0x0. 0x0 is the address of NULL value i.e. 0. You cannot access 0x0 memory address. Now if you compare two pointers which are pointing to memory address 0x0 i.e. NULL then it will be same only as the NULL value is 0 by default 0 0 replyShare bharti commented Aug 24, 2017 reply Follow flag @saxena0612 okk so u mean to say no matter it is global assignment or local assignment of null , both will point to Same address 0x0 . that is the reason of condition being true . 0 0 replyShare saxena0612 commented Aug 24, 2017 reply Follow flag Yup ! compile their address for better understanding! 0 0 replyShare bharti commented Aug 24, 2017 i reshown by bharti Aug 25, 2017 reply Follow flag @saxena0612 yeah ! I did :) Thank you 0 0 replyShare Hemant Parihar commented Aug 25, 2017 reply Follow flag @saxena0612 Any resources for your this statement. "when you point pointer to NULL then it means that it is pointing to the memory address 0x0." (Always) 0 0 replyShare saxena0612 commented Aug 25, 2017 reply Follow flag According to C Standard Document section 6.3.2.3: An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.55) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function. 1 1 replyShare Please log in or register to add a comment.
0 0 votes Ans is A. Global variables (pointers or data members) are always assigned a default value at compilation. Hence the default value for gPtr is NULL. Abbas2131 answered Aug 24, 2017 Abbas2131 comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Global variables are by default NULL and the ASCII value of NULL is 0.So 0=0 is true hence output would be EQUAL! sandeepjkh answered Aug 25, 2017 sandeepjkh comment Share Follow 0 reply Please log in or register to add a comment.