首先注意,const int * p 和int const *p 是一样的,并且不管是不是*p,即使const int i和int const i也是一样的,所以我们接下来只讨论int const * p和int * const p的不同 对于这种问题,我们只用将const 的位置固定,然后再看后面的东西,一般规则是后面的东西不能在进行赋值或者修改.例如下面: #include<stdio.h> int main(int argc,char *argv[]) { int i = 10; int…
本文只是一篇学习笔记,是看了<彻底搞定C指针>中的相关篇幅后的一点总结,仅此而已! 一.先搞清const int *p与int const *p的区别 它们的区别就是:没有区别!! 无论谁在前面都没有影响!所以const int *p与int const *p用法一样! 二.const int *p的用法 #include <stdlib.h> #include <stdio.h> #include <string.h> int main(int argc,…
C++ char*,const char*,string,int 的相互转换   1. string转const char* string s ="abc";const char* c_s = s.c_str(); 2. const char*转string    直接赋值即可 const char* c_s ="abc";string s(c_s);  3. string转char* string s ="abc";char* c;consti…
看例子: int sloth = 3; const int *p1 = &sloth; int * p2 const = &sloth; 这样申明的话,不允许使用p1来修改sloth的值,但是p1可以指向其他的地址: 可以利用p2修改sloth的值,但是p2不允许指向其他地址. 第二个例子: 1. int gorp = 16; int chips = 12; const int *p_snack = &gorp *p_snack = 20; (X) p_snack = &c…
一.int 和string的相互转换 1 int 转化为 string c++ //char *itoa( int value, char *string,int radix); // 原型说明: // value:欲转换的数据. // string:目标字符串的地址. // radix:转换后的进制数,可以是10进制.16进制等. // 返回指向string这个字符串的指针 int aa = 30; char c[8]; itoa(aa,c,16); cout<<c<<endl;…
char & operator[](int i);const char & operator[](int i);/*const char & operator(int i);*/编译出错:error C2556: 'const char &MyString::operator [](int)' : overloaded function differs only by return type from 'char &MyString::operator [](int…
http://blog.csdn.net/zhangheng837964767/article/details/33783511 关键问题点:const 属于修饰符 ,关键是看const 修饰的位置在那里1.const int *a这里const 修饰的是int,而int定义的是一个整值因此*a 所指向的对象 值 不能通过 *a 来修改,但是 可以重新给 a 来赋值,使其指向不同的对象eg:       const int *a = 0;       const int b = 1;      …
来源:https://blog.csdn.net/zhangheng837964767/article/details/33783511 关键问题点:const 属于修饰符 ,关键是看const 修饰的位置在那里1.const int *a这里const 修饰的是int,而int定义的是一个整值因此*a 所指向的对象 值 不能通过 *a 来修改,但是 可以重新给 a 来赋值,使其指向不同的对象eg:       const int *a = 0;       const int b = 1;  …
This interview question come from a famous communication firm of china. : ) #include <iostream> #include <stdio.h> #include <string.h> #include <conio.h> using namespace std; int main() { float a = 1.0f; cout << cout <<…
来源:http://blog.csdn.net/qianchenglenger/article/details/16949689 1.int i 传值,int & i 传引用 int i不会回带参数,而int &i可以回带参数,如 #include <iostream> void test1(int i) { i = 7; } void test2(int &i) //要限制参数改动,可以加const限制 { i = 7; } int main() { int t1 =…