凡将一个字符串常量存储在内存中? [英] Where will a constant string be stored in memory?

查看:133
本文介绍了凡将一个字符串常量存储在内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我们使用这种类型的code在我们的C编程。

sometimes we use this type of code in our c programming.

char *p = "Sam";

下面恒定字符串萨姆的地址将被存储在字符指针p。如今这里结果
我要问哪里的萨姆将被储存在哪里?

Here the address of constant character string "Sam" is going to be stored in char pointer p. now here
i want to ask where the Sam is going to be stored ?

推荐答案

该标准没有规定这一点。通常情况下,字符串(萨姆)将被存储在数据部分,在一个只读页面。

The standard doesn't specify this. Typically the string literal ("Sam") will be stored in the data section, in a read-only page.

至于 P 本身,这取决于它是否是自动的还是静态的。

As for p itself, it depends on whether it is automatic or static.

这篇关于凡将一个字符串常量存储在内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆