c 2b 2b const cast

Solutions on MaxInterview for c 2b 2b const cast by the best coders in the world

showing results for - "c 2b 2b const cast"
Ana
18 Jul 2020
1// const_cast
2#include <iostream>
3using namespace std;
4
5void print (char * str)
6{
7  cout << str << '\n';
8}
9
10int main () {
11  const char * c = "sample text";
12  print ( const_cast< char *>(c) );
13  return 0;
14}
15
16
17// const_cast
18#include <iostream> 
19using namespace std; 
20
21int fun(int* ptr) 
22{ 
23	return (*ptr + 10); 
24} 
25
26int main(void) 
27{ 
28	const int val = 10; 
29	const int *ptr = &val; 
30	int *ptr1 = const_cast<int *>(ptr); 
31	cout << fun(ptr1); 
32	return 0; 
33}