C++指针学习

C++指针学习路径与实践指南 阅读详情

指针的声明有两种风格

int*  x,y;//  这里要尽量写成int* x; int* y; 起强调作用

int  *x,y;//声明了一个指针和一个int变量

指针是有类型限值的

不能用int型指针去接收double型指针变量


Void指针

void 指针可以指向任意类型的地址

void 指针的操作很受限值(指针比较,给函数传递参数,复制给void类型的指针),不能用此类型的指针去操作对象。

不能用 *p ,不能用p++(,因为不知道存储类型,也就不知道++对应的步长是多少)


关于指针作为形参的问题


#include <STRING.H>
#include <STDIO.H>

void reset(int *p)
{
	*p=0;
	p=0;
}
int main()
{
	int ival(1024);
	printf("%d\r\n",ival);
	int *x=&ival;
	int *p=&ival;
	
	printf("%d\r\n",*p);
	reset(p);

	printf("%d\r\n",*p);
	printf("%d\r\n",*x);
	return 0;
}

两点新需要注意

1.指向的地址内存放的值发生了变化

2.指向的地址没有发生变化。(以前没有关注过这一条)


C++学习之指针 指针是C++语言中非常重要的概念,它提供了对内存中数据的直接访问方式。指针存储了一个变量的内存地址,可以通过指针来访问和操作该变量。以下是指针的一些基本介绍:定义指针:在C++中,可以使用(星号)来声明一个指针变量。例如,int* ptr;声明了一个名为ptr的指向整数的指针变量。需要注意的是,指针变量在声明时应初始化为一个有效的内存地址。获取变量地址:使用取地址运算符可以获取一个变量的内存地址。例如,将ptr指向num的地址。解引用指针:使用解引用运算符可以访问指针所指向的变量的值。例如,会输出。 阅读详情

相关推荐

从机械到数字:EC11旋转编码器与ESP32的PWM控制艺术

本文详细解析了EC11旋转编码器与ESP32的PWM控制技术,探讨了如何将机械旋转动作转换为精确的数字信号控制。通过硬件连接、信号处理和软件优化等实践技巧,开发者可以构建高效的人机交互系统,适用于智能照明、电机控制等多种应用场景。

android的专栏 785

C++指针

/ 1.int main(){// const修饰指针 - 常量指针// 特点:指针的指向可以修改,但是指针指向的值不可以修改//常量指针p = &b;//正确,指针的指向可以修改// *p = 21;//错误,指针指向的值不可以修改}

m0_58233509的博客 869

避坑指南:QCustomPlot鼠标事件冲突解决方案(左键拖动vs右键框选)

本文深入解析QCustomPlot在QT框架下的高级交互实现,重点解决左键拖动与右键框选的冲突问题。通过自定义事件处理和QRubberBand技术,提供了一套完整的无冲突交互方案,帮助开发者优化数据可视化应用的用户体验。

moss5的博客 660

-------int & 引用

这里引用“落辰衰”大佬的解释: 1、int; int是C++关键字,表示整型,其大小是32位有符号整型,表示的范围是-2,147,483,648 到 2,147,483,647;在声明和定义变量时使用,它表示的意思是所声明或所定义的变量为整型变量。 如果其用于函数参数时,其传递方向为值传递,即只能将实参的值传递给形参,而不能将 形参的值传递给实参。 例如:通过这种方式去进行交换两个数...

张洪基 3509

广告推荐算法 - 学习笔记(持续更新中)

本篇博客,是我用来记录学习广告推荐算法的一些笔记和总结。王喆:"深度"学习计算广告计算广告系统的核心目标是通过数据、算法和技术,在合适的场景下,将最相关的广告精准推送给目标用户,同时实现广告主媒体平台和用户之间的多方利益最大化。广告主:需求方核心目标:通过精准投放广告,最大化转化(如点击、购买)并控制成本,提升投资回报率(ROI)。关键行为:广告创建,定向设置,预算与出价策略,效果监控媒体平台:供给方核心目标:最大化广告收入,同时保持用户体验以避免用户流失。

qq_39748832的博客 2197

论文深度解析:基于大语言模型的城市公园多维度感知解码与公平性提升

本文针对城市公园感知测量的精细化不足与公平性评估缺口,提出了一套融合社交媒体数据与大语言模型(LLM)的创新分析框架。通过领域适配微调开发的Park-Perception-LLM模型,实现了对感知可达性、可用性、吸引力三大核心维度83%-91%的高精度分类。将该感知指标创新性地融入增强两步浮动集水区法(E2SFCA),以香港高密度城市为案例,系统揭示了公园质量与数量的空间不平等及错配模式。借助多元回归模型,深入挖掘了公园内部特征、宏观建成环境、微观街道景观及时间因素对感知的影响机制。

May the Force be with you 1014

C++中 引用符&,以int&举例说明

本篇是摘抄自byteH的一篇,int&

robinhjwy的博客 8547

DFI协议时序

参数名称典型值应用场景关键影响tcmd_lat1-2个时钟周期命令与地址锁存同步地址错误风险tphy_wrlat1-2个时钟周期写操作响应速度写带宽与延迟2-3个时钟周期写操作端到端延迟系统吞吐量1-2个时钟周期连续写命令间隔信号干扰与资源冲突tphy_rdlat1-2个时钟周期读操作响应速度读带宽与延迟trddata_en由CL决定(如0.41 ns)读数据返回时间系统延迟10-20 ps写数据与命令对齐数据丢失风险<1 µs低功耗模式切换。

qq_43134430的博客 5103

[C++基础]019_指针和引用(int*、int&、int*&、int&*、int**)

相信很多CPPers跟我一样,曾经在指针和引用里徘徊了很久很久。经常弄混指针和引用,尤其是见到如题中列出那些用法,着实是伤脑经。 后来,在项目中用着用着,就能搞清楚区别了,算是会用吧。然而,对于一个Programmer,最忌讳的就是不知其所以然,会用和懂是两番天地。停留在会用的人,始终是原地打转;而懂的人,一通百通,能举一反三。 本文,就如题的指针和引用的用法做一个介绍。 首先我们来普及一下...

weixin_33969116的博客 622

Carla运行显示The following component(s) are required to run this program:DirectX Runtime |nvapi64.dll没有被

Carla运行显示The following component(s) are required to run this p 参考: 【1】EPIC 启动游戏提示The following component(s) are required to run this program:... - 『悬赏问答区』 - 吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cnhttps://www.52pojie.cn/thread-1485651-1-1.html ...

anananajiushiwo的博客 5万+

86、高斯过程:学习、应用与自动相关性确定

本文介绍了高斯过程回归的基本原理及其在实际应用中的关键技术,重点探讨了通过最大化对数似然函数来学习模型超参数的方法,并详细阐述了自动相关性确定(ARD)技术如何用于评估输入变量的重要性。文章涵盖了从协方差函数定义、梯度计算到优化算法的应用流程,并通过流程图和表格形式总结了核心步骤与公式。此外,还讨论了贝叶斯处理方式及异方差问题的建模策略,展示了高斯过程在复杂数据建模中的灵活性与强大能力。

android的专栏 114

C++知识点

1.new申请对堆空间,方括号里必须是整型, int * p =new int [10] () 加括号全部初始化为0 int * p =new int [10] {1,2,3,4,5} 加大括号按位置初始化 动态分配一个空数组是合法的 char *p =new char[0] (合法) 释放动态数组,delete[]p 是销毁数...

weixin_30878361的博客 225

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

C++学习笔记之指针(基础)

并且,在进行关系比较前,需要。

韵律咖啡馆 1209

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

C++算法学习专题:双指针

双指针(Two Pointers)是一种非常实用且高效的算法思想,主要用于处理线性数据结构(如数组、链表等)中的特定问题。这种技术通过使用两个指针(或索引)在数据结构中协同遍历,能够显著优化算法的时间复杂度。

2401_89119815的博客 994

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

【C++学习】引用与指针

C++学习笔记,引用与指针

whb78952的博客 593

深入学习C++中的指针,这是一个核心但可能有些难以理解的概念

以下内容将从基础到高级,结合控制台代码示例,帮助你彻底掌握指针的用法和注意事项。虽然你要求基础学习,但简单介绍智能指针(unique_ptr, shared_ptr)可以帮助避免手动内存管理的错误。指针是一个变量,存储的是另一个变量的内存地址。释放时先释放每行(delete[] matrix[i]),再释放指针数组(delete[] matrix)。如果你有具体问题(例如某个指针用法的疑惑或想实现特定功能),告诉我,我可以提供更详细的代码或解释!指针可以指向另一个指针,形成多级指针。

专注于前沿技术的探索与实践,热衷于从代码逻辑、架构设计到行业应用等多维度深挖技术本质。期待在技术之路上与你共同成长~ 1018

C++学习笔记(七:指针)

这篇C++学习笔记系统整理了指针相关的核心知识,主要包含以下内容:1. 内存构成详解(代码区、栈区、堆区等5大分区) 2. 指针核心概念:定义、运算符(&/*)、指针运算规则 3. 指针与数组/字符串的关联操作 4. 指针作为函数参数和返回值的应用 5. 高级指针类型:指针数组、指向指针的指针 6. 引用机制及其与指针的区别 7. 典型应用场景如数据交换、动态内存管理等 笔记通过大量代码示例(如指针遍历数组、选择排序实现等)配合内存布局图示,深入解析指针的底层原理和使用技巧,特别强调指针运算、多维数

ShangguanLuli的博客 827

C++学习系列(4):C++数组与指针

数组是一组。

Azperk的博客 443

C++学习之this指针与友元

C++学习之this指针与友元

qq_27302885的博客 1096

学习C++的第七天(指针)

7.1指针的基概念7.1指针的基概念。

2401_83927585的博客 1036

C++学习-入门到精通-【6】指针

以使用指针变量的按引用传递方式传递一个变量实质上并没有按引用传递任何东西,传递的其实是这个变量的指针(这个变量的地址),将该地址复制到函数对应的指针形参中。上面的例子中使用一个引用变量来访问array对象中的元素,前面加上了一个const表明,在这个作用域中,item这个别名不应该修改它引用的值。一个好的程序应该是遵循最小特权原则的,也就是一个函数是有足够的权限访问函数参数中的数据来完成指定的任务的,但是权限不能过大。当一个指针变量的值为。在之前写过的代码中我们也遵循着这样的原则,还记得之前使用过的。

PLKDTHFS的博客 802

C++指针学习总结

刚学完指针做一下学习总结. 指针的概念 内存-有内存单元构成. 我们一般关注内存单元的地址(编号)和内容(存放的数据). C++中每个变量都有分配有确定的内存空间. 使用变量名可以直接访问内存中的数据; 通过变量的地址也可以间接访问内存中的数据. 例如: int a; //四个字节(四个内存单元),将其第一个内存单元的地址作为变量的地址. C++中允许定义一种特殊变量,用于存放某变量...

cmomo99d的博客 419

C++学习笔记(十三)——指针

指针(Pointer)是 C++ 中的一种特殊变量,它存储的是另一个变量的内存地址,而不是具体的值。 指针有以下作用: 直接操作内存地址,提高效率。 动态内存分配,如 new 和 delete。 数组与字符串的操作,如遍历数组。 函数参数传递,提高性能,避免数据拷贝。 实现数据结构,如链表、树等。

weixin_45857378的博客 919

C++学习笔记——指针与引用(一)

C++学习笔记——指针与引用(一)

weixin_42923076的博客 287

cpp学习笔记之const和指针的组合

实践解决const和指针的组合问题

weixin_48645141的博客 320
上一篇: 手动编译cpp文件(window下)
下一篇: 发达国家服务业占GDP的 80%
writeeee
博客等级 码龄18年 35粉丝 76原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值