On Tue, Aug 12, 2008 at 8:26 PM, Johannes Weiner <hannes@xxxxxxxxxxxx> wrote:> Hi,>> "Belisko Marek" <marek.belisko@xxxxxxxxx> writes:>>> On Tue, Aug 12, 2008 at 7:28 PM, Santosh Pradhan>> <santosh.pradhan@xxxxxxxxx> wrote:>>> Hi All,>>> I am new to this group and I have a question regarding following C program.>>>>>> #include<stdio.h>>>>>>> #define NAME "santosh">>>>>> int main()>>> {>>> char *p_name = NAME;>>> char *q_name = NAME;>>> if (p_name == q_name)>>> printf("Hello, World\n");>>> return 0;>>> }>>>>>> When I compile this test program, it always prints "Hello, World".>>>>> Both pointers point to same address (NAME) that's the reason why you>> always get Hello World in output. :)>> You might run cpp over this code and rethink your answer :)OK to be precisious char*p_name is pointer which point to array ofchars(santos) and both pointers point to the beginning of same array,that's the reason why condition is alway TRUE ;)>>>> My Question:>>>>>> i) Does compiler do any optimization automatically to make both the pointers>>> have same address ?>>>>>> ii) How does this happen?>> You can debug your code in e.g Kdevelop and see exactly what happens.>>>>>> iii) Will both the pointers be same always?>> Yes, both point to same variable.>> That's incorrect, "santosh" is not a variable.OK, NAME is array of chars ;)>> Hannes> Marek -- Marek BeliškoRuská Nová Ves 21908005 PrešovSlovakiahttp://binaural.ifastnet.com��.n��������+%����w�j)p���{.n����z�ޖw�n'���q���b�������v��m�����Y�����