zoukankan      html  css  js  c++  java
  • Pointers and Strings

    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 ";
    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().

    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.

  • 相关阅读:
    Spring 事务管理
    016 sleep,wait,yield,join区别
    013 GC机制
    011 CountDownLatch,CyclicBarrier和Semaphore
    012 public等关键字可见性
    010 JVM类加载
    009 JVM内存结构以及GC机制
    008 BlockingQueue理解
    python3 正则表达式
    python django
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/3310524.html
Copyright © 2011-2022 走看看