c语言中的指针、双指针和三指针 [英] pointers, double pointers and triple pointers in c

查看:97
本文介绍了c语言中的指针、双指针和三指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
有人可以吗告诉我给定代码中第二个 printf 语句中的引用流程?

 #include<iostream>
 using namespace std;
 char *c[] = {"ENTNG","NST","AMAZI","FIRBE"};
 char **cp[] = {c+3,c+2,c+1,c};
 char ***cpp = cp;
 int main(){
 cout<<(**++cpp);
 cout<<(*--*++cpp+3);
 cout<<(*cpp[-2]+3);
 cout<<(cpp[-1][-1]+1);
 return 0;
 }

我试图理解指针、双指针和三指针的概念.有人可以告诉我这段代码是如何工作的以及解决方案背后的概念吗?提前谢谢.

I am trying to understand the concept of pointers, double pointers and triple pointers. Can please somebody tell me how this code works and the concept behind the solution? Thanx in advance.

推荐答案

单个指针是可以指向特定数据类型的内存位置的数据类型.在这种情况下,它是 char 所以我们假设它是一个char指针,它只能指向一个char变量,即只能保存一个字符变量的地址.双指针可以存放单指针的地址,三指针可以存放双指针的地址.

A single pointer is that data type which can point to a memory location of a particular data type.. In this case, it is char so we assume it is a char pointer and it can point only to a char variable, that is, it can hold address of a character variable only. A double pointer can hold the address of a single pointer, and a triple pointer can hold the address of a double pointer.

在您的代码中,第一个指针 'c' 是一个双指针,它本身包含 cstrings.cstrings 是单个字符指针.那么 'cp' 和 'cpp' 都是三重指针.

In your code, the first pointer 'c' is a double pointer which holds cstrings in itself. cstrings are single char pointers. then 'cp' and 'cpp' both are triple pointers.

至于其余代码,它非常混乱,看起来像一场噩梦.你最好阅读一些关于指针和基本 C++ 编程的资源.我会推荐斯坦福大学的埃里克·罗伯茨爵士 (Sir Eric Roberts) 的 C++ 中的编程抽象.另请参阅智能指针.

As for the rest of the code,it is pretty messed up and looks like a nightmare. You had better read some resource on pointers and basic C++ programming. I would recomment Programming abstractions in c++ by Sir Eric Roberts from Stanford. Also see smart pointers.

这篇关于c语言中的指针、双指针和三指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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