使指针的中间;它有效吗?
Making the middle of a pointer NUL; does it work?
可能的重复:
在C字符串中" 0"后的内存会发生什么?
可以制作指针的第三元素nul(' 0'),然后"擦除"指针剩余的元素?
假设您在谈论C风格字符串,那么是:
char s[] = "abcdefgh"; // s = "abcdefgh"
// (actually contains 9 characters: "abcdefgh ")
s[3] = ' '; // s = "abc"
// (still contains 9 characters, but now: "abc efgh ")
请注意,此时s[3]
之外的字符尚未神奇地消失 - 只是显示字符串或将其传递到采用C风格字符串的任何功能,导致字符串仅显示为包含三个字符。您仍然可以做,例如
s[3] = 'x'; // s = "abcxefgh"
// (still contains 9 characters, but now: "abcxefgh ")
相关文章:
- 调整大小后指向元素值的指针unordered_map有效?
- 如何在工厂方法中返回指向基于基础操作系统的派生类的有效指针
- 为什么在引用指针时将 const 放在 & 符号的左侧有效,而在右侧则无效?
- C++ 返回指向函数内定义的静态数组的指针是否有效?
- 通过指针调用模板类成员函数 [为什么这是有效的 c++]?
- free():在有效指针异常中-使用流读取巨大文件时
- 释放 std::vector 中指针内存的最有效方法是什么?
- C++ 常量指向文字的指针有效吗?
- 是否存在将长整型转换为指针有效的情况
- 将指针传递给函数在简单的情况下有效,但在"class" -izing 之后不起作用
- 在映射中插入更多元素后,指向 QMap 中元素的指针是否仍然有效?
- 指向派生类的指针中的"static_cast<Base*>(static_cast<void*>(派生))"何时有效?
- 如何有效地使用 std::async 对指针数组执行操作
- 当程序从该函数调谐器时,指向在函数中声明和定义的某些 C 字符串的指针不再有效.为什么?
- EIGEN地图类:将C阵列映射到VectorXD指针以有效的方式
- 如何检查指针后面的对象是否有效或已删除?
- 什么是 gcc Linux x86-64 C++中的有效指针
- 是仅用于有效指针的%p说明符
- 有效指针的含义
- 超过指向 C 样式字符串的有效指针的值