C++学习笔记 --- 指针1
2011-10-18 17:23
239 查看
活用指针进行for循环(多种写法),结果都是输出:“ Now is the time ”
#include <iostream> // A character array. char msg[] = "Now is the time\n"; //////////////////////////////////////// // The main() function. //////////////////////////////////////// int main() { char* cp; // A pointer to char. int i; // An integer subscript // Pointer access, pointer notation. for (cp = msg; *cp; cp++) std::cout << *cp; // Subscript access, subscript notation. for (i = 0; msg[i]; i++) std::cout << msg[i]; // Pointer access, subscript notation. for (cp = msg; cp[0]; cp++) std::cout << cp[0]; // Subscript access, pointer notation. for (i = 0; *(msg+i); i++) std::cout << *(msg+i); // Pointer and subscript access, pointer notation. for (i = 0, cp = msg; *(cp+i); i++) std::cout << *(cp+i); // Pointer and subscript access, subscript notation. for (i = 0, cp = msg; cp[i]; i++) std::cout << cp[i]; return 0; }
相关文章推荐
- c++ 学习笔记(47)-C++中两个类中互相包含对方对象的指针问题
- 【C++学习笔记】指针小结
- c++ 11学习笔记--智能指针
- C++学习笔记 --- 指针2
- C++学习笔记之数据类型(2)数组、向量、指针
- C++学习笔记(13)——利用对象、引用、指针调用虚函数
- 智能指针auto_prt的使用(c++学习笔记)
- C/C++学习笔记:智能指针详解
- C++学习笔记:C的继承与超越——指针与引用
- 【c++学习笔记】指针
- 笔记:C++学习之旅---指针
- C++学习笔记之函数指针
- C/C++学习笔记----指针的理解
- c++入门学习笔记指针篇
- c++ 模板学习笔记:类模板模拟auto_ptr智能指针(权哥)
- (c/c++学习笔记八)指针数组和指针的指针
- C++ 学习笔记(2)变量和基本类型(复合类型:引用、指针)、const、constexpr、typedef(using)、auto、decltype
- C/C++学习笔记四(指针、数组)
- C++学习笔记(1)void*指针
- C++学习笔记之 函数重载和函数指针在一起