cpp学习笔记(一)

cpp学习笔记(一)

由于已经有了一定的编程基础了,cpp的前几章节和c很像,稍微有一点点不同,因此大略的看看

这些笔记是我看的书籍的大纲 ,边看书,边回想大纲里面的内容,写一些简单的测试例子

基础的1-9章

1 绪论
2 C++程序的组成部分
3 使用变量和常量
4 管理数组和字符串
5 使用表达式、语句和运算符
6 控制程序流程
7 使用函数组织代码
8 指针
9 引用

第一章

为何c++是软件开发的标准
    过程化,结构化,面向对象化
开发c++程序的步骤
    源代码,编译,链接,运行
输入,编译和链接第一个c++程序

不能忽略警告

第二章

c++程序的组成部分
    头文件,main函数,命名空间,注释
各部分如何协同工作
函数及其用途

第三章

如何声明和定义变量和常量
    (unsigned,signed)
bool,int,char,float,double
如何给变量赋值以及操纵这些值
如何将变量显示到屏幕上
注意变量的大小,不要预估int的大小,了解他们

第四章

什么是数组以及如何声明它们 和c相同
什么是字符串,如何使用字符数组表示字符串
    char数组可用
    string表示字符串

第五章

什么是语句
什么是语句块
什么是表达式
如何根据条件不同的程序代码
什么是真值,如何使用它

第六章

函数及其组成部分
如何声明和定义函数
    局部变量
    全局变量
如何向函数传递参数
    形参
    默认参数

如何从函数返回一个值

函数重载
内联函数
递归函数
函数的工作原理
    抽象
    划分RAM
        全局名称空间
        自由存储
        寄存器
        代码空间和堆栈

第七章

什么是循环?如何使用它们
如何创建各种循环
深度嵌套if...else语句的代替品

goto,while,do..while,
continue,break,for,switch,

第八章

什么是指针
如何声明和使用指针
什么是自由存储已经如何操纵内存

一定要初始化所有指针 *ptr

指针和数组名
指针在自用存储区
new && delete

//指向的值不变 *p不变 p可变
const int*pone;
int const *pone2;
//地址不变 *p可变 p不变
int*const ptwo

第九章

什么是引用
引用和指针的区别何在
如何创建和使用引用
引用的局限性是什么
如何按引用将值和对象传入和传出函数

引用不能为空,不能重新赋值

空指针和空引用
使用引用以提高效率
传递const指针

尽可能按照引用传递参数
尽量使用const来保护引用和指针
不要使用返回堆或者自由存储的引用
//
//  main.cpp
//  simple_use_1_7
//
//  Created by bikang on 16/9/21.
//  Copyright (c) 2016年 bikang. All rights reserved.
//

#include <iostream>
#include <string.h>
using namespace std;

typedef unsigned short int UNSHORT;
//定义常量
#define STUDENT_COUNT 15
const int aconst = 16;
enum COLOR{YELLOW,BLUE,WHITE,BLACK};
enum COLOR_2{YELLOW2=10,BLUE2,WHITE2=30,BLACK2};

void tc3();
void tc4();
void tc6();
int sum(int a,int c=1);
double sum(double a,double b);

inline int doubleData(int d);

int doublePlus(int n);

void swap(int &x,int &y){
    int temp;
    temp = x;
    x = y;
    y = temp;
}

void tc7();
void tc9();


int main(int argc, const char * argv[]) {
    //tc3();
    //tc4();
    //tc6();
    //tc7();
    tc9();
    return 0;
}

void tc9(){

    int x = 1,y = 2;
    cout << x << "," << y << endl;
    swap(x, y);
    cout << x << "," << y << endl;

    int &rx  = x;
    //rx = y;
   // &rx = y;//faild
    cout << rx << endl;



}

void tc7(){
    int a = 12;
    int *p = &a;
    cout << *p <<endl;
}

void tc6(){
    cout << sum(11,2)<<endl;
    cout << sum(11)<<endl;
    cout << sum(11.1,22.3)<<endl;
    cout << doubleData(22) << endl;
    cout << doublePlus(4) << endl;
}

int doublePlus(int n){
    if(n <= 1){
        return 1;
    }else{
        return doublePlus(n-1)*n;
    }
}

inline int doubleData(int d){
    return 2*d;
}

double sum(double a,double b){
    return a+b;
}

int sum(int a,int c){
    return a+c;
}


void tc4(){
    int i,j;
    int arr[3][2] ={{1,2},{3,4},{5,6}};
    //arr[3][3] = 11;
    for(i=0;i<3;i++){
        for(j=0;j<2;j++){
            cout << arr[i][j]<<",";
        }
        cout << endl;
    }

    char buffer[80] = {'\0'};
    //cin.get(buffer,79);

    strcpy(buffer, "good char array!");
    cout << buffer<<endl;
    strncpy(buffer, "abcdef!", 3);
    cout << buffer;
    cout << "endl"<<endl;


    //string
    string str1 = "hehe";
    string str2 = str1;
    str2 = "go";
    cout << str1 << endl;
    cout << str2 << endl;


    return;
}


void tc3(){
    cout << "t3 end\n";
    cout << sizeof(long)<<endl;
    UNSHORT dshort = 12;
    cout << dshort<<endl;
    cout << aconst << endl;
    COLOR c1 = YELLOW;
    COLOR_2 c2 = BLUE2;
    cout <<"c1="<<c1 <<"c2="<<c2<<endl;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值