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".
My Question:
i) Does compiler do any optimization automatically to make both the pointers have same address ?
ii) How does this happen?
iii) Will both the pointers be same always?
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
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".
My Question:
i) Does compiler do any optimization automatically to make both the pointers have same address ?
ii) How does this happen?
iii) Will both the pointers be same always?
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