如何找到字符串的内存地址? [英] How do I find the memory address of a string?

查看:62
本文介绍了如何找到字符串的内存地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有心理障碍,我知道我应该知道这一点,但我需要一点帮助.

I am having a mental block and I know I should know this but I need a little help.

如果我像这样声明一个字符串变量:

If I declare a string variable like this:

    string word = "Hello";

如何找到Hello"的内存地址?

How do I find the memory address of "Hello"?

这就是我想要做的......

This is what I am trying to do...

编写一个函数,它接受一个参数,一个字符串的地址,并打印一次该字符串.(注意:你需要使用一个指针来完成这部分.)

Write a function that takes one argument, the address of a string, and prints that string once. (Note: you will need to use a pointer to complete this part.)

但是,如果提供了第二个参数 int 类型并且该参数非零,则该函数应打印字符串的次数等于该函数在该点被调用的次数.(注意,字符串被打印的次数不等于第二个参数的值;它等于函数到目前为止被调用的次数.)

However, if a second argument, type int, is provided and is nonzero, the function should print the string a number of times equal to the number of times that function has been called at that point. (Note that the number of times the string is printed is not equal to the value of the second argument; it is equal to the number of times the function has been called so far.)

推荐答案

使用:

请注意,这些调用返回的指针不必必须是 std::string 对象正在操作的基础数据.

Note that the pointer returned by either of these calls doesn't have to be the underlying data the std::string object is manipulating.

这篇关于如何找到字符串的内存地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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