onst和volatile分析

来源:互联网 发布:三国演义动画知乎 编辑:程序博客网 时间:2024/04/29 21:38
一、const和volatile分析

  1、const修饰变量

  # 在c语言中const修饰的变量时只读的,其本质还是变量

  # const修饰的变量会在内存占用空间

  # 本质上const只对编译器有用,在运行时无用

  原来const不是真的常量

onst和volatile分析

# 在C语言中const修饰的数组是只读的

  #const修饰的数组空间不可以被改变

  const int A[5] = {1, 2, 3, 4, 5}

  int *p = (int *)A;

  int i = 0;

  for(i=0; i<5; i++)

  {

  p[i] = 5-i;//报错

  }

  3、const修饰指针

  # const int *p; //p可变,p指向的内容不可变

  # int const *p; //p可变,p指向的内容不可变

  # int *const p; //p不可变,p指向的内容可变

  # const int *const p; //p不可变, p指向的内容不可变

http://v.17173.com/playlist_16648348?retcode=0
http://v.17173.com/playlist_16652883?retcode=0
http://v.17173.com/playlist_16654641?retcode=0
http://v.17173.com/playlist_16657769?retcode=0
http://v.17173.com/playlist_16659068?retcode=0
http://v.17173.com/playlist_16659895?retcode=0
http://v.17173.com/playlist_16661064?retcode=0
http://v.17173.com/playlist_16662125?retcode=0
http://v.17173.com/playlist_16663174?retcode=0
http://v.17173.com/playlist_16664810?retcode=0
http://v.17173.com/playlist_16665458?retcode=0
http://v.17173.com/playlist_16666559?retcode=0
http://v.17173.com/playlist_16668088?retcode=0
http://v.17173.com/playlist_16669573?retcode=0
http://v.17173.com/playlist_16747281?retcode=0
http://v.17173.com/playlist_16748181?retcode=0
http://v.17173.com/playlist_16748993?retcode=0
http://v.17173.com/playlist_16749763?retcode=0
http://v.17173.com/playlist_16750655?retcode=0
http://v.17173.com/playlist_16757239?retcode=0
http://v.17173.com/playlist_16757776?retcode=0
http://v.17173.com/playlist_16758843?retcode=0
http://v.17173.com/playlist_16759417?retcode=0
http://v.17173.com/playlist_16760157?retcode=0
http://v.17173.com/playlist_16760903?retcode=0
http://v.17173.com/playlist_16761521?retcode=0
http://v.17173.com/playlist_16763013?retcode=0
http://v.17173.com/playlist_16763743?retcode=0
http://v.17173.com/playlist_16764530?retcode=0
http://v.17173.com/playlist_16765270?retcode=0
http://v.17173.com/playlist_16765842?retcode=0
http://v.17173.com/playlist_16766530?retcode=0
http://v.17173.com/playlist_16767315?retcode=0
http://v.17173.com/playlist_16768553?retcode=0
http://v.17173.com/playlist_16768997?retcode=0
http://v.17173.com/playlist_16769523?retcode=0
http://v.17173.com/playlist_16770218?retcode=0
http://v.17173.com/playlist_16770814?retcode=0
http://v.17173.com/playlist_16771317?retcode=0
http://v.17173.com/playlist_16772091?retcode=0
http://v.17173.com/playlist_16772758?retcode=0
http://v.17173.com/playlist_16773477?retcode=0
http://v.17173.com/playlist_16773960?retcode=0
http://v.17173.com/playlist_16774386?retcode=0
http://v.17173.com/playlist_16774960?retcode=0
http://v.17173.com/playlist_16775600?retcode=0
http://v.17173.com/playlist_16776142?retcode=0
http://v.17173.com/playlist_16776614?retcode=0
http://v.17173.com/playlist_16777034?retcode=0
http://v.17173.com/playlist_16777585?retcode=0


0 0
原创粉丝点击