Wednesday, 6 August 2014

Find output of the following program.


           char *someFun()
            {
            char *temp = “string constant";
            return temp;
            }
            int main()
            {
            puts(someFun());
            }

Answer:
            string constant
Explanation:

            The program suffers no problem and gives the output correctly because the character constants are stored in code/data area and not allocated in stack, so this doesn’t lead to dangling pointers. 

No comments:

Post a Comment