Re: A simple query about memory mgmt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 youalways get Hello World in output. :)> 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.>> iv) Will it differ in other platforms like prop. Unix (AIX/HP-UX etc.) and> Win?>> Any kind of help is appreciated.>> Sorry, if it is not the right place to ask this :(.>> Thanks in advance.>> Regards,> Santosh>


-- Marek BeliškoRuská Nová Ves 21908005 PrešovSlovakiahttp://binaural.ifastnet.com��.n��������+%����w�j)p���{.n����z�ޖw�n'���q���b�������v��m�����Y�����


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux