pointer to constant

Solutions on MaxInterview for pointer to constant by the best coders in the world

showing results for - "pointer to constant"
Lorenzo
11 Jun 2016
1#include<iostream>
2
3int main()
4{	
5	int number_1{100};
6    int number_2 {200};
7    
8    //the data(value) pointed by the pointer is constant 
9	const int *some_ptr {&number_1};
10    *some_ptr = 300 ; //Error
11    *some_ptr = &number_2 ; // ok => the aderss is different 
12  
13  	//the adress pointed by the pointer is constant 
14  	int *const some_ptr {&number_1} ;
15  	some_ptr = &number_2 //error => the adress of the pointer is constant 
16    *some_ptr = 123 // ok 
17    
18    // the adress and the data is constant 
19   	const int const *some_ptr{&number_1};
20  	*some_ptr = 32; // error
21	some_ptr = &number_2; // error  
22    
23    return 0;
24}
Jordy
07 Apr 2020
1//the data(value) pointed by the pointer is constant 
2	const int *some_ptr {&number_1};
3//the adress pointed by the pointer is constant 
4  	int *const some_ptr {&number1} ;
5
similar questions
queries leading to this page
pointer to constant