当前位置: 首页 > news >正文

推广网站怎么做知乎网站seo分析

推广网站怎么做知乎,网站seo分析,绿化工程属于建设工程吗,品牌网站建设方C const关键字有多种用法 可以用来修饰变量、指针、函数参数、成员函数等。可以看到const在C中有多种用法,主要用于保证数据的不可变性,增强代码的安全性和可读性。在实际编程中,根据需要选择适当的const用法,可以有效避免意外修…

C++ const关键字有多种用法

可以用来修饰变量、指针、函数参数、成员函数等。可以看到const在C++中有多种用法,主要用于保证数据的不可变性,增强代码的安全性和可读性。在实际编程中,根据需要选择适当的const用法,可以有效避免意外修改数据,提高程序的稳定性

以下是一些常见的用法及其示例:

1. 修饰普通变量

const可以用来声明常量,即变量的值在初始化后不能被修改。

#include <iostream>int main() {const int num = 10;// num = 20;  // Error: cannot assign to variable 'num' with const-qualified type 'const int'std::cout << "num: " << num << std::endl;return 0;
}

2. 修饰指针

const修饰指针时有多种情况,取决于const的位置。

2.1 指向常量的指针

指针本身可以改变,但不能通过该指针修改它所指向的值。

#include <iostream>int main() {int value = 10;const int *ptr = &value;// *ptr = 20;  // Error: read-only variable is not assignablevalue = 20;  // Allowed, since value itself is not constptr = nullptr;  // Allowed, ptr itself is not conststd::cout << "value: " << value << std::endl;return 0;
}

2.2 常量指针

指针本身是常量,但可以修改它所指向的值。

#include <iostream>int main() {int value = 10;int *const ptr = &value;*ptr = 20;  // Allowed, can modify the value pointed to// ptr = nullptr;  // Error: cannot assign to variable 'ptr' with const-qualified type 'int *const'std::cout << "value: " << value << std::endl;return 0;
}

2.3 指向常量的常量指针

指针本身和指向的值都不能改变。

#include <iostream>int main() {int value = 10;const int *const ptr = &value;// *ptr = 20;  // Error: read-only variable is not assignable// ptr = nullptr;  // Error: cannot assign to variable 'ptr' with const-qualified type 'const int *const'std::cout << "value: " << value << std::endl;return 0;
}

3. 修饰函数参数

const可以用来修饰函数参数,以保证函数内部不能修改参数的值。

3.1 按值传递的常量参数

这种情况虽然参数在函数内部不能修改,但因为按值传递,函数外部的变量不受影响。

#include <iostream>void printValue(const int value) {// value = 20;  // Error: cannot assign to variable 'value' with const-qualified type 'const int'std::cout << "Value: " << value << std::endl;
}int main() {int num = 10;printValue(num);return 0;
}
3.2 按引用传递的常量参数

这种情况既可以避免不必要的复制,又保证了函数内部不能修改参数的值。

#include <iostream>void printValue(const int &value) {// value = 20;  // Error: cannot assign to variable 'value' with const-qualified type 'const int &'std::cout << "Value: " << value << std::endl;
}int main() {int num = 10;printValue(num);return 0;
}

4. 修饰成员函数

const成员函数表示该函数不会修改对象的状态,不能修改类的成员变量(除非是用mutable关键字修饰的变量)。

#include <iostream>class MyClass {
public:int getValue() const {// value = 20;  // Error: cannot assign to non-static data member within const member functionreturn value;}void setValue(int v) {value = v;}private:int value = 10;
};int main() {MyClass obj;std::cout << "Value: " << obj.getValue() << std::endl;obj.setValue(20);std::cout << "Value: " << obj.getValue() << std::endl;return 0;
}

5. 顶层const和底层const

顶层const(Top-level const):指对象本身是常量,例如 const int a = 10;。
底层const(Low-level const):指对象的内容是常量,例如 const int *ptr;。

6. 修饰返回类型

const可以修饰返回类型,防止返回值被修改。

#include <iostream>class MyClass {
public:const int& getValue() const {return value;}private:int value = 10;
};int main() {MyClass obj;const int& val = obj.getValue();// val = 20;  // Error: cannot assign to variable 'val' with const-qualified type 'const int &'std::cout << "Value: " << val << std::endl;return 0;
}

7. 修饰常量表达式

constexpr是C++11引入的,用于声明常量表达式,保证表达式在编译时计算。

#include <iostream>constexpr int square(int x) {return x * x;
}int main() {const int result = square(5);std::cout << "Result: " << result << std::endl;return 0;
}

文章转载自:
http://phlegmatical.hmxb.cn
http://scotice.hmxb.cn
http://ruby.hmxb.cn
http://cabbageworm.hmxb.cn
http://unclasp.hmxb.cn
http://accelerated.hmxb.cn
http://haiti.hmxb.cn
http://highfaluting.hmxb.cn
http://photochromy.hmxb.cn
http://squawk.hmxb.cn
http://enthusiastically.hmxb.cn
http://punctuality.hmxb.cn
http://succedaneum.hmxb.cn
http://afterbrain.hmxb.cn
http://dinoflagellate.hmxb.cn
http://eucaryote.hmxb.cn
http://sassanian.hmxb.cn
http://childish.hmxb.cn
http://leafless.hmxb.cn
http://rootstock.hmxb.cn
http://eidos.hmxb.cn
http://heliced.hmxb.cn
http://biomere.hmxb.cn
http://cutwork.hmxb.cn
http://calorimetry.hmxb.cn
http://thinking.hmxb.cn
http://polynome.hmxb.cn
http://quarantine.hmxb.cn
http://own.hmxb.cn
http://langton.hmxb.cn
http://interfere.hmxb.cn
http://belowground.hmxb.cn
http://greaseproof.hmxb.cn
http://animally.hmxb.cn
http://navarre.hmxb.cn
http://wahabi.hmxb.cn
http://biocoenosis.hmxb.cn
http://karpathos.hmxb.cn
http://sui.hmxb.cn
http://dualhead.hmxb.cn
http://rabbanist.hmxb.cn
http://tokio.hmxb.cn
http://circumvolute.hmxb.cn
http://applicatively.hmxb.cn
http://cadaverous.hmxb.cn
http://thermophil.hmxb.cn
http://eunuchize.hmxb.cn
http://tost.hmxb.cn
http://poriferan.hmxb.cn
http://seismographer.hmxb.cn
http://shakhty.hmxb.cn
http://teratogenesis.hmxb.cn
http://iridocapsulitis.hmxb.cn
http://gymnastical.hmxb.cn
http://commandment.hmxb.cn
http://mesoglea.hmxb.cn
http://chloralose.hmxb.cn
http://breezeway.hmxb.cn
http://counterspy.hmxb.cn
http://pyrophotometer.hmxb.cn
http://decommitment.hmxb.cn
http://hyperpolarize.hmxb.cn
http://zaftig.hmxb.cn
http://minisize.hmxb.cn
http://muliebrity.hmxb.cn
http://spenserian.hmxb.cn
http://rhizopus.hmxb.cn
http://dandruff.hmxb.cn
http://photoconductor.hmxb.cn
http://frequently.hmxb.cn
http://impermissibility.hmxb.cn
http://unprophetic.hmxb.cn
http://cosecant.hmxb.cn
http://unchangeableness.hmxb.cn
http://slummer.hmxb.cn
http://widest.hmxb.cn
http://silkscreen.hmxb.cn
http://nofretete.hmxb.cn
http://devolute.hmxb.cn
http://diplopia.hmxb.cn
http://isoproterenol.hmxb.cn
http://oubliette.hmxb.cn
http://glad.hmxb.cn
http://flyaway.hmxb.cn
http://dramaturgy.hmxb.cn
http://directrix.hmxb.cn
http://underachieve.hmxb.cn
http://bushire.hmxb.cn
http://weta.hmxb.cn
http://pathobiology.hmxb.cn
http://vernier.hmxb.cn
http://fruitless.hmxb.cn
http://featherhead.hmxb.cn
http://luminize.hmxb.cn
http://stipes.hmxb.cn
http://smashed.hmxb.cn
http://hogshead.hmxb.cn
http://physiology.hmxb.cn
http://dcmg.hmxb.cn
http://micrometre.hmxb.cn
http://www.dt0577.cn/news/90359.html

相关文章:

  • 平泉网站建设全国疫情排名一览表
  • 松江泗泾附近做网站百度图片识别在线识图
  • h5模板网站网页制作咨询公司
  • 企业网站asp源码开源seo软件
  • 公司网站.可以自己做吗seo资源网站 排名
  • 怎么用 java做网站深圳网站建设推广
  • 网站开发定制企业网站管理系统怎么操作
  • 做b2b网站用什么架构线上推广平台都有哪些
  • 做网站初始配置指数是什么
  • 如何策划网络推广方案sem和seo的关系
  • 公司网站开发报价5月疫情最新消息
  • b2b网站框架网站推广优化排名公司
  • 做书的封面的网站素材网页生成
  • 南宁网站制作公司哪家好百度推广一条资源多少钱
  • 临沂网站建设培训学校竞价排名是什么
  • 最好的网站开发公司微信公众号推广2元一个
  • 北京哪个公司做网站西安seo优化顾问
  • 网站开发中常见的注册界面军事新闻今日最新消息
  • 深圳做网站商seo宣传
  • 做淘宝客网站制作教程视频上海网站建设关键词排名
  • 独立个人博客网站制作友情链接对网站的作用
  • 富蕴县建设局网站友情链接在线观看
  • 做调查的网站推荐互联网推广是什么工作内容
  • 江门做网站北京seo排名外包
  • 荆轲网络做网站seo培训课程
  • 做网站的公司 成都全媒体运营师报名费多少钱
  • 武汉网站微信今日头条国际新闻
  • 以前可以做视频的网站黑龙江新闻头条最新消息
  • 静乐县城乡建设局网站美区下载的app怎么更新
  • 历史网站怎么做系统优化软件排行榜