The special relationship between arrays and pointers extends to C-style strings.Consider the following code:
char flower[10]="rose";
cout<<flower<<"s are red\n";
The name of an array is the address of ite first element,so flower in the cout statement is the address of the char element containing the character r.

The cout object assumes that the address of a char is the address of a string,so it prints the character at that address and then continues printing characters until it runs into the null character(\0).

In short,if you give cout the address of a character,it prints everything from that character to the first null character that follows it.

The crucial element here is not that flower is an array name but that flower acts as the address of a char.This implies that you can use a pointer-to-char variable as an argument to cout,also,because it,too,is the address of a char.Of course,that pointer should point to the beginning of a string.

Pointers and Strings的更多相关文章

  1. How to distinguish between strings in heap or literals?

    Question: I have a use case where I can get pointers of strings allocated either in memory or litera ...

  2. SQLite源程序分析之sqlite3.c

    /****************************************************************************** ** This file is an a ...

  3. 分享O'Reilly最新C语言指针数据

    1.推荐书名 Understanding.and.Using.C.Pointers.pdf 2. 本书目录 Table of Content Chapter 1. Introduction Chapt ...

  4. JavaScript 堆内存分析新工具 OneHeap

    OneHeap 关注于运行中的 JavaScript 内存信息的展示,用可视化的方式还原了 HeapGraph,有助于理解 v8 内存管理. 背景 JavaScript 运行过程中的大部分数据都保存在 ...

  5. 《Peering Inside the PE: A Tour of the Win32 Portable Executable File Format》阅读笔记二

    Common Sections The .text section is where all general-purpose code emitted by the compiler or assem ...

  6. PE Header and Export Table for Delphi

    Malware Analysis Tutorial 8: PE Header and Export Table 2. Background Information of PE HeaderAny bi ...

  7. Dr.memory

    Run Dr.memory on visual c++ 2013 Title: Dr. Memory Command: C:\Program Files (x86)\Dr. Memory\bin\dr ...

  8. getopt使用

    参考: http://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html http://en.wikipedia.org ...

  9. C++ - main()函数参数

    main()函数及其参数说明 main()函数主要形式: int main(void) int main(int argc, char *argv[]) = int main(int argc, ch ...

随机推荐

  1. memcached和redis区别

    Memcached:是高性能分布式内存缓存服务器,本质是一个内存 key-value 数据库,但不支持数据持久化,服务器关闭后,数据全丢失.只支持 key-value 结构. Redis:将大部分数据 ...

  2. iOS 适配/ autoLayout基本知识

    历史 iPhone3GS.iPhone4\4s:没有屏幕适配最早开发里面的程序全部都是写死的 iPad 旋转出来之后 Autoresizing问世iPhone5\5c\5s兼容各种不同的情况 系统适配 ...

  3. vue 同页面不同参数

    项目:详情页中有一个模块为更多产品,点击也是跳转到详情页,也就是相同路由,不同参数. 试过的方法:用this.$router.push,并没有任何反应,没有任何请求,页面也未重新加载,用this.$e ...

  4. Leetcode 之Binary Tree Preorder Traversal(42)

    树的先序遍历.定义一个栈,先压入中间结点并访问,然后依次压入右.左结点并访问. vector<int> preorderTraversal(TreeNode *root) { vector ...

  5. html添加新元素兼容和访问

    <!DOCTYPE html> <html> <head> <title>Creating an HTML Element</title> ...

  6. go run/ go install/ go build / go get的区别

    go run 运行当个.go文件 go install 在编译源代码之后还安装到指定的目录 go build 加上可编译的go源文件可以得到一个可执行文件 go get = git clone + g ...

  7. 【转载】viewLoad、viewDidLoad的一些事

    viewLoad和viewDidLoad都可以用来在视图载入的时候,初始化一些内容 viewDidLoad此方法只有当view从nib文件初始化的时候才被调用.viewDidLoad用于初始化,加载时 ...

  8. hdu 1024(滚动数组+动态规划)

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. debian 7 安装 rz sz lrzsz

    https://blog.csdn.net/hchaoyangming/article/details/51582749

  10. hdu多校 2

    ... 后面四个小时都在挂机很难受. 1010 裸的逆序对 //#pragma comment(linker, "/stack:200000000") //#pragma GCC ...