Re: A simple query about memory mgmt

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

 



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 :)

>> 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.

	Hannes

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[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