搬砖:函数名&函数名取地址

C++笔记之关于函数名前的取址符 在C++中,函数名通常被解释为指向函数的地址。函数名可以被视为函数的指针,它指向函数的起始位置,因此可以用于函数指针和函数指针数组的操作。需要注意的是,函数名不是普通变量,因此有一些限制和特殊情况,如函数重载、成员函数指针等,需要特殊的语法来处理。但总的来说,函数名在C++中可以被视为指向函数的地址。都用于获取函数的地址,并且它们都可以用作函数指针的初始化。在C++中是等效的,因为函数名在大多数情况下会隐式地转换为指向函数的指针。需要注意的是,C++通常会自动将函数名转换为指向函数的指针,因此。 阅读详情

函数名&函数名取地址

有时看到如下的代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

/*****************************/

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

 

void test()

{

    printf("123456\n");

}

 

int main(int argc, char *argv[])

{

    printf("0x%x\n",test);

    printf("0x%x\n",&test);

}

 

[root@localhost pht]# ./a.out

0x8048328

0x8048328

按照&运算符本来的意义,它要求其操作数是一个对象,但函数名不是对象(函数是一个对象),本来&test是非法的,但很久以前有些编译器已经允许这样做,
c/c++标准的制定者出于对象的概念已经有所发展的缘故,也承认了&test的合法性。

因此,对于test和&test你应该这样理解,test是函数的首地址,它的类型是void (),&test表示一个指向函数test这个对象的地址,
它的类型是void (*)(),因此test和&test所代表的地址值是一样的,但类型不一样。test是一个函数,&test表达式的值是一个指针!


跟此问题类似的还有对一个数组名取地址。
int a[100];
printf("%p\n", a);
printf("%p\n", &a[0]);

打印值一样。
但是数组名a,指向的是具有100个int类型的组数;
&a[0]指向的是元素a[0]。
即他们的值相同,但指向的类型不同。

标准在其rationale中解释了这个问题,摘录如下:
6.5.3.2 Address and indirection operators
Some implementations have not allowed the & operator to be applied to an array or a function.
(The construct was permitted in early versions of C, then later made optional.) The C89 Language
Committee endorsed the construct since it is unambiguous, and since data abstraction is
enhanced by allowing the important & operator to apply uniformly to any addressable entity.

【加密社】私钥碰撞器,秒杀市面上的碰撞器 基于上述的逻辑和代码,开发了ETH挖掘器(图1.1)这里有个亮点是:1.很多开发者在判断地址是否有效的环节上,用的是查询余额,其实这是不对的,查询余额你可能只能查询对应代币的余额,例如usdt,eth等但是如果用查询交易次数就不一样了,你只要是交易过,我就认为是有效钱包,这样的速度比查询余额要快,也要更准确。2.rpc节点可配置。 阅读详情

相关推荐

2D激光slam数据集的下载与测试

参考博客: https://blog.youkuaiyun.com/qq_24894159/article/details/81265991 https://blog.youkuaiyun.com/fk1174/article/details/52673413#commentBox 数据集下载与生成 下载数据集 下载网址: http://ais.informatik.uni-freiburg.de/slamevaluation/datasets.php 进去网站后点你想下载的对应的"download log file" 然后你

老李的博客 4025

函数名,函数名取地址,函数名取值之间的区别

#include typedef void (*cfp_t)(int a); cfp_t calls_table[3]={NULL,}; void test(int a) { printf("test();\n"); } int main(void) { printf("************0**********\n"); printf("test:%d\n

欧阳海宾 1957

PICO4 VR开发调试神器:用Live Preview Plugin实现电脑串流,告别反复打包烧录的繁琐流程

本文详细介绍了PICO4 VR开发中如何使用Live Preview Plugin实现电脑串流,显著提升开发效率。通过实时预览和调试功能,开发者可以避免反复打包烧录的繁琐流程,特别适用于Unity环境下的VR应用开发。文章涵盖环境配置、连接设置、实时调试技巧及性能优化方案,是PICO4开发者的必备指南。

weixin_34110970的博客 418

函数名&函数名取地址

转自http://my.oschina.net/mavericsoung/blog/174110 有时看到如下的代码:  01 /*****************************/ 02 #include 03 #include

coobeedongzhou的专栏 4347

VS2022错误列表高效处理:从复制到Excel表格的完整指南

本文详细介绍了在Visual Studio 2022中高效处理错误列表的实用技巧,重点讲解了如何将错误信息一键复制并粘贴到Excel表格中。通过基础操作、自定义视图、筛选功能及常见问题解决方案,帮助开发者将杂乱的编译错误整理成清晰、可排序、可筛选的数据表,极大提升了团队协作、错误分析和项目管理的效率。

weixin_28837817的博客 359

C语言对函数取地址,C语言函数名以及取地址的区别和联系

有时看到如下的代码:/*****************************/#include #include #include void test(){printf("123456\n");}int main(int argc, char *argv[]){printf("0x%x\n",test);printf("0x%x\n",&amp;test);}[root@localhost p...

weixin_35511255的博客 2484

数据采集卡架构与PCIe优化设计详解

数据采集卡(DAQ)作为工业自动化中的关键设备,其核心在于模数转换(ADC)和数字信号处理技术。现代系统普遍采用PCIe总线架构,通过DMA传输和时钟同步技术实现高速数据采集。在信号调理环节,可编程增益放大器(PGA)和抗混叠滤波器确保信号质量;而Σ-Δ型ADC则提供高达24位的分辨率。实际应用中,从电力监测到机床振动分析,数据采集卡需要结合具体场景优化配置。通过合理的PCB布局和EMI防护设计,可以有效提升系统在工业环境中的可靠性。

weixin_29168675的博客 912

C语言 什么时候用取地址什么时候不用取地址,&符号讲解

情况一: &amp;是一个取地址运算符 &amp;a是一个表达式,其功能是求变量a的地址 scanf函数的一般形式为:scanf("格式控制字符串",地址列表); scanf输入的是地址,printf输出的是值,如下举例说明 #include&lt;stdio.h&gt; void main() { int a,b,c; printf("input the value of a,b,c\n"); scanf("%d %d %d",&amp;a,&amp;b,&amp;c); printf("a=%d

梁同学与Android 3万+

基于MATLAB的鲁棒主成分分析(Robust PCA)图像去噪

鲁棒主成分分析(Robust PCA)是一种有效的图像去噪方法,它能够在保持图像细节的同时去除噪声。本文将介绍如何使用MATLAB实现基于鲁棒PCA的图像去噪,并提供相应的源代码。它假设噪声是随机的、高斯分布的,并将图像分解为一个低秩矩阵和一个稀疏矩阵的和。低秩矩阵表示图像的结构和纹理信息,稀疏矩阵表示图像中的噪声和细节信息。接下来,我们将图像矩阵减去均值,得到规范化的图像矩阵。然后,我们将灰度图像转换为矩阵形式,并计算图像的均值。通过分离出低秩矩阵和稀疏矩阵,我们就得到了去噪后的图像和残差图像。

DevRevolt的博客 1125

深入理解 DDR5 Bank Group 与并行调度机制

Bank Group架构和并行调度机制,是DDR5性能跃升的核心秘密!理解它们才能写出高效调度程序,设计出性能强劲又稳定的DDR5系统。🎯记住:Bank Group不是简单的分组,而是高速并行的“魔法钥匙”,巧用它,你的DDR5设计将爆发惊人性能!

weixin_43199439的博客 313

C语言函数名、&函数名、*函数名

C语言函数名、取地址函数名、解引用函数名关系

chen_dunyun的博客 1万+

Qt/C++ 音视频开发 - FFmpeg 安卓版

通过将 FFmpeg 集成到 Qt/C++ 项目中,我们可以实现强大且灵活的音视频处理功能。本文介绍了在安卓平台上使用 FFmpeg 的基本步骤,包括初始化、解码、处理和编码等。实际应用代码示例展示了如何在安卓设备上播放视频。

走向CTO的路上... 1192

C++中的函数名与函数名取地址

的相关代码时,遇到了一些疑惑,特意记录下来。运算符本来的意义,它要求其操作数是一个对象。根据上面所讲,此时的。是整个数组的首地址。虽然它两的值相同,但是类型不同。其它情况下会被转化为指向该函数的指针,那么这时的。是没有区别的,那么它们两本质的区别是什么呢?除过上面的两种情况外,还有第三种情况,那就是。是数组名,表示的是整个数组的首地址;的操作数时,它的类型才是函数对象;的值是一样的,那它们的类型一样吗?这个函数对象的地址。可以取得这个函数对象的地址。都可以得到函数的地址,也就是。的类型是函数对象,所以。

qq_41596730的博客 1121

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

C/C++知识分享:函数名和取地址的区别以及联系

有时看到如下的代码: /*****************************/ #include&lt;stdio.h&gt; #include&lt;string.h&gt; #include &lt;stdlib.h&gt; void test(){printf("123456\n");} int main(intargc,char*argv[]) {printf("0x%x\n",test); printf("0x%x\n",&amp;test);} [[e...

C语言C++学习俱乐部:765860056 895

深度学习工具包 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&#39;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 = &quot;R. B. Palm&quot;, title = &quot;Prediction as a candidate for learning deep hierarchical models of data&quot;, year = &quot;2012&quot;,}```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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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 &lt; 0.10, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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 &lt; 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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&lt;0.12, &#39;Too big error&#39;);```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(&#39;state&#39;,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 &lt; 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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 &lt; 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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 &lt; 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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 &lt; 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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 &lt; 0.1, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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 &lt; 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free &quot;Bitdeli Badge&quot;)

指针的基础知识及&取地址运算

指针式C语言中一种特殊的变量,其作用是保存其他变量的地址。可以把指针想象成一个指向某个特定位置的箭头,这个箭头指向的就是其他变量在内存中的存储地址。如果指针要指向一个整型变量,那么数据类型就是int;如果指向一个字符型变量,数据类型就是char。

📖在读学生📖 1154

指针(*)、取地址(&)、解引用(*)与引用(&)

指针(*)、取地址(&amp;)、解引用(*)与引用(&amp;) C++ 提供了两种指针运算符,一种是取地址运算符 &amp;,一种是间接寻址运算符 *。 指针是一个包含了另一个变量地址的变量,您可以把一个包含了另一个变量地址的变量说成是"指向"另一个变量。变量可以是任意的数据类型,包括对象、结构或者指针。 指针与取地址 例程: int main() { int num = 3; int* p = &amp;num; // 将变量num的地址取出来,存到指针p中 printf(

weixin_44966641的博客 4万+

详解C语言中&的使用(取地址符)

文章目录什么是取地址符使用方法探测&amp;变量的类别指针变量赋值 什么是取地址符 顾名思义,就是获取当前变量的内存地址,想要获得那个变量的地址,就用&amp;后面跟上那个变量。 使用方法 在输出的时候后面跟上变量名就行,看一下这个例子: #include &lt;stdio.h&gt; //头文件 #include &lt;windows.h&gt; struct player //...

1匹黑马 4万+

c语言函数名取地址,C语言函数名以及取地址的区别和联系

有时看到如下的代码:/*****************************/#include #include #include void test(){printf("123456\n");}int main(int argc, char *argv[]){printf("0x%x\n",test);printf("0x%x\n",&amp;test);}[[emailprotected...

weixin_33356324的博客 1415

关于&的引用与取地址 区分

在习惯了C语言的程序员眼里 , &amp; 这个符号的意思就是取地址和对位进行与运算 , 但在C++中 , &amp; 被重载多了一种意思 , 就是引用。 在这里我就不介绍位与运算了 , 我先介绍一下取地址运算 ,在学习指针的时候我们就已经用过了取地址符了 , 使用方法为在变量前面加上&amp;即可。 接下来是介绍引用 , 简单来说 , 引用就是被引变量的另一个名字 , 当改变引用值时 , 被引值也会改变 , 因为它们两就是同一个值 , 另外 , 引用不能脱离对象单独存在 , 引用是依附与对象...

是鲤鱼啊 3993

详解C++中指针(*)、取地址(&)、解引用(*)与引用(&)的区别

对于c语言中指针的操作符有两个:&amp;和*。对于&amp;,就是“取地址”的意思。但对于*,翻译为“解引用”,字面意思不好理解,即使看了后面内容才知道不过是“取指针指向的地址的内容”,"*"的作用是引用指针指向的变量值,引用其实就是引用该变量的地址,“解”就是把该地址对应的东西解开,解出来,就像打开一个包裹一样,那就是该变量的值了,所以称为“解引用”。也就是说,解引用是返回内存地址中保存的值。...

yhc166188的博客 9874

GoLang之取地址符&、指针

GoLang之取地址符&、指针

weixin_52690231的博客 3545

数组名 、 函数名 和 数组名取地址 、 函数名取地址

#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; void test() { printf("123456\n"); } int main() { char a[10]; printf("&amp;a:%p, a:%p, &amp;a[0]:%p \n", &am...

QQ839787886的博客 818

C语言中指针与取地址符&详解

关于指针与取地址符 1.什么是指针? (1)首先,我们要明白什么叫做指针变量名,对于 int *p,这里的指针变量名不是 p 而是 p ,类似与 Java 中定义数组是 int [] array ,所以我习惯将 p 叫做 int * 类型 (2)通俗的来说:指针就是地址,通过这段地址就可以找到以它为地址的那个内存单元 【保存地址使用的就是指针变量,所以是用变量名p=&amp;a,而不是p = &a...

Indomite的博客 1万+
上一篇: 搬砖:%P 和%X有什么区别
下一篇: 面:面反,真是水的一塌糊涂
nedwons
博客等级 码龄9年 311粉丝 572原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值