栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

NEFU C++课程总结(第二章)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

NEFU C++课程总结(第二章)

C++在非面向对象方面的一些特性         一、标准输出流和标准输入流:

    cin>>x>>y;
    sort(x,y);
    cout<<"x= "< 输出格式符hex、dec、oct分别对应16进制、10进制、8进制 
#include
using namespace std;
int main(){
    int x=25;
    cout< 用setw()来控制域宽,头文件为 
#include
#include
using namespace std;
int main(){
    int x=25;
    cout< 
        二、灵活的局部变量说明:  

c++允许在代码块中的任何地方说明局部变量

#include 
#include 
using namespace std;
int main()
{
    for (int i = 0; i < 5; i++)
    {
        cout << i; //只可在for循环中使用
    }
}
         三、结构、联合和枚举名可直接作为类型名:

#include 
#include 
using namespace std;
int main()
{
    struct student{
        int id;
        char name;
    };
    student s1;
    
}
四、const修饰符------常数说明:

const 类型 标识符 =常数

#include 
#include 
using namespace std;
const int size=30;
int main()
{
}
const 类型 * 标识符(标识符声明为一个指针,它所指向的值为常量)类型 * const 标识符(将该类型声明为一个指针常量)
五、内联函数:

通过inline声明,编译器在编译的时候首先在调用出使用函数体本身的语句替换掉函数调用语句,然后进行编译。这样就不需要进行函数跳转,效率会高一些。(优点)

#include 
#include 
using namespace std;
// const int size=30;
inline int min(int x,int y){
    return x 
六、带有缺省参数的函数:

C++在说明函数原型的时候,可以为一个或多个参数指定缺省值

#include 
#include 
using namespace std;
// const int size=30;
inline int min(int x=5,int y=3){
    return x 
七、重载函数 reload:
#include
using namespace std;
int sroot(int a){
    return sqrt(a);
}
long long sroot(long long a){
    return sqrt(a);
}
double sroot(double a){
    return sqrt(a);
}
int main(){
    int x;
    long long y;
    double z;
    cin>>x>>y>>z;
    cout<<"sqrt(i)= "<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/767254.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号