update dir
This commit is contained in:
8
const/funciton_const/condition1/condition1.cpp
Normal file
8
const/funciton_const/condition1/condition1.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(){
|
||||
const int *ptr;
|
||||
*ptr=10; //error
|
||||
}
|
9
const/funciton_const/condition1/condition2.cpp
Normal file
9
const/funciton_const/condition1/condition2.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(){
|
||||
const int p = 10;
|
||||
const void *vp = &p;
|
||||
void *vp = &p; //error
|
||||
}
|
12
const/funciton_const/condition1/condition3.cpp
Normal file
12
const/funciton_const/condition1/condition3.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
const int *ptr;
|
||||
int val = 3;
|
||||
ptr = &val; //ok
|
||||
int *ptr1 = &val;
|
||||
*ptr1=4;
|
||||
cout<<*ptr<<endl;
|
||||
|
||||
}
|
BIN
const/funciton_const/condition2/condition1
Executable file
BIN
const/funciton_const/condition2/condition1
Executable file
Binary file not shown.
10
const/funciton_const/condition2/condition1.cpp
Normal file
10
const/funciton_const/condition2/condition1.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int main(){
|
||||
|
||||
int num=0;
|
||||
int * const ptr=# //const指针必须初始化!且const指针的值不能修改
|
||||
int * t = #
|
||||
*t = 1;
|
||||
cout<<*ptr<<endl;
|
||||
}
|
8
const/funciton_const/condition2/condition2.cpp
Normal file
8
const/funciton_const/condition2/condition2.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int main(){
|
||||
|
||||
const int num=0;
|
||||
int * const ptr=# //error! const int* -> int*
|
||||
cout<<*ptr<<endl;
|
||||
}
|
BIN
const/funciton_const/condition2/condition3
Executable file
BIN
const/funciton_const/condition2/condition3
Executable file
Binary file not shown.
8
const/funciton_const/condition2/condition3.cpp
Normal file
8
const/funciton_const/condition2/condition3.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int main(){
|
||||
|
||||
const int num=10;
|
||||
const int * const ptr=# //error! const int* -> int*
|
||||
cout<<*ptr<<endl;
|
||||
}
|
BIN
const/funciton_const/condition3/condition1
Executable file
BIN
const/funciton_const/condition3/condition1
Executable file
Binary file not shown.
10
const/funciton_const/condition3/condition1.cpp
Normal file
10
const/funciton_const/condition3/condition1.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
|
||||
const int p = 3;
|
||||
const int * const ptr = &p;
|
||||
cout<<*ptr<<endl;
|
||||
|
||||
}
|
Reference in New Issue
Block a user