For beginners in C/C programming, pointers are one of the most difficult concepts to understand. Many students are troubled by this, and many developers try to avoid using pointers. However, understanding pointers is crucial, so let's start with the basics.
What is a pointer?
A pointer is a data type, similar to int
, float
, etc. The syntax for declaring a pointer is to add *
after the type name. For example, a pointer to an integer is declared as int *
, and a pointer to a custom structure mytype
is declared as mytype *
.
The pointer points to the memory address of the variable. int *
Storing the address of integer variables, mytype *
Storing the address of mytype
variables.
Example:
<code class="language-c ">#include<iostream> int main(){ int value = 42; int* p = &value; // p指向value的内存地址std::cout </iostream></code>
Main pointer operator
In addition to storing the address of a variable, pointers have two main operations: dereference and pointer arithmetic.
Decision
Use the *
operator to dereference the pointer to access the value in the memory unit pointed to by the pointer.
<code class="language-c ">#include<iostream> int main(){ int var = 42; int *p = &var; // p指向var的内存地址*p = 21; // 修改var的值为21 }</iostream></code>
An uninitialized pointer is very dangerous because it can point to anywhere in memory, causing the program to crash or undefined behavior.
Pointer arithmetic
Pointer arithmetic allows modifying the value of a pointer (i.e., memory address). Pointers can be added and subtracted, or added and subtracted with integers. It should be noted that the step size of the pointer addition and subtraction operation is the byte size of the data type pointed to. For example, if p
is a pointer to an integer, p
will make p
point to the address of the next integer.
Pointer arithmetic needs to be used with caution, as it allows direct operation of memory.
<code class="language-c ">#include<iostream> int main(){ int v = 21; int w = 42; int *p = &w; // p指向w p ; // p指向v *p = 1; // v的值加1 std::cout </iostream></code>
As shown in the example, we can modify the value of a variable that is not directly assigned through pointer arithmetic.
Empty pointer
Similar to the special position of the number 0 in numbers, nullpointer ( nullptr
) also plays an important role in pointers. A null pointer means that the pointer does not point to any valid memory address. Before using a pointer, be sure to check whether it is empty to avoid program crashes or errors.
<code class="language-c ">#include<iostream> int* foo(int value){ static int answ = 42; if(answ == value){ return &answ; } else { return nullptr; } } int main(){ int *p = foo(21); if (p != nullptr) { // 使用p } }</iostream></code>
Key points
To sum up, we learned:
- A pointer is a variable that stores memory addresses.
- Always initialize the pointer, uninitialized pointer may cause the program to crash.
- Always check if it is empty before dereference to the pointer.
- Use pointer arithmetic with caution.
Hope this guide will help you better understand pointers in C/C. Continue to learn and explore more!
The above is the detailed content of Pointer, a weird beast, suitable for beginners and beyond. For more information, please follow other related articles on the PHP Chinese website!

ai合并图层的快捷键是“Ctrl+Shift+E”,它的作用是把目前所有处在显示状态的图层合并,在隐藏状态的图层则不作变动。也可以选中要合并的图层,在菜单栏中依次点击“窗口”-“路径查找器”,点击“合并”按钮。

ai橡皮擦擦不掉东西是因为AI是矢量图软件,用橡皮擦不能擦位图的,其解决办法就是用蒙板工具以及钢笔勾好路径再建立蒙板即可实现擦掉东西。

虽然谷歌早在2020年,就在自家的数据中心上部署了当时最强的AI芯片——TPU v4。但直到今年的4月4日,谷歌才首次公布了这台AI超算的技术细节。论文地址:https://arxiv.org/abs/2304.01433相比于TPU v3,TPU v4的性能要高出2.1倍,而在整合4096个芯片之后,超算的性能更是提升了10倍。另外,谷歌还声称,自家芯片要比英伟达A100更快、更节能。与A100对打,速度快1.7倍论文中,谷歌表示,对于规模相当的系统,TPU v4可以提供比英伟达A100强1.

ai可以转成psd格式。转换方法:1、打开Adobe Illustrator软件,依次点击顶部菜单栏的“文件”-“打开”,选择所需的ai文件;2、点击右侧功能面板中的“图层”,点击三杠图标,在弹出的选项中选择“释放到图层(顺序)”;3、依次点击顶部菜单栏的“文件”-“导出”-“导出为”;4、在弹出的“导出”对话框中,将“保存类型”设置为“PSD格式”,点击“导出”即可;

ai顶部属性栏不见了的解决办法:1、开启Ai新建画布,进入绘图页面;2、在Ai顶部菜单栏中点击“窗口”;3、在系统弹出的窗口菜单页面中点击“控制”,然后开启“控制”窗口即可显示出属性栏。

Yann LeCun 这个观点的确有些大胆。 「从现在起 5 年内,没有哪个头脑正常的人会使用自回归模型。」最近,图灵奖得主 Yann LeCun 给一场辩论做了个特别的开场。而他口中的自回归,正是当前爆红的 GPT 家族模型所依赖的学习范式。当然,被 Yann LeCun 指出问题的不只是自回归模型。在他看来,当前整个的机器学习领域都面临巨大挑战。这场辩论的主题为「Do large language models need sensory grounding for meaning and u

ai移动不了东西的解决办法:1、打开ai软件,打开空白文档;2、选择矩形工具,在文档中绘制矩形;3、点击选择工具,移动文档中的矩形;4、点击图层按钮,弹出图层面板对话框,解锁图层;5、点击选择工具,移动矩形即可。

引入密集强化学习,用 AI 验证 AI。 自动驾驶汽车 (AV) 技术的快速发展,使得我们正处于交通革命的风口浪尖,其规模是自一个世纪前汽车问世以来从未见过的。自动驾驶技术具有显着提高交通安全性、机动性和可持续性的潜力,因此引起了工业界、政府机构、专业组织和学术机构的共同关注。过去 20 年里,自动驾驶汽车的发展取得了长足的进步,尤其是随着深度学习的出现更是如此。到 2015 年,开始有公司宣布他们将在 2020 之前量产 AV。不过到目前为止,并且没有 level 4 级别的 AV 可以在市场


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

SublimeText3 Chinese version
Chinese version, very easy to use