String storage locations in C/

Source: Internet
Author: User

Code:

1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 voidFunChar**p) {7     //char* s = "World";8     CharS[] =" World";9printf"Point s =%p\n", s);Ten*p =s; Oneprintf"Point p =%p\n",*p); A } -  - intMain () { the  -     Char*p ="Hello"; -printf"Point p =%p\n", p); -cout<<"func Start"<<Endl; +Fun (&p); -cout<<"Func End"<<Endl; +printf"Point p =%p\n", p); Acout<<p<<Endl; at  -     return 0; -}

Output:

Point P = 0x400accfunc startpoint s = 0x7ffe10660100point p = 0x7ffe10660100func Endpoint p = 0x7ffe10660100 '

If the 8th line of code is commented and replaced by the 7th line of the comment, the output is

Point P = 0x400ac2func startpoint s = 0x400aa0point p = 0x400aa0func Endpoint p = 0x400aa0world

Analysis:

The constant string is stored in the literal constant area, and the character array is stored on the stack.

String storage locations in C/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.