How to use the static_cast operator in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

int main() 
{
	int *a = new int();
	*a = 13;

	cout << *a << " : " << a << endl;

	void *b = static_cast<void*>(a);
	cout << " : " << b << endl;

	int *c = static_cast<int*>(b);
	cout << *c << " : " << c << endl;

	return 0;
}


/*
run:

13 : 003F4FB0
   : 003F4FB0
13 : 003F4FB0

*/

 



answered Mar 30, 2018 by avibootz

Related questions

1 answer 154 views
154 views asked Dec 2, 2022 by avibootz
2 answers 162 views
162 views asked Apr 25, 2020 by avibootz
1 answer 229 views
2 answers 168 views
1 answer 143 views
143 views asked Mar 24, 2018 by avibootz
...