+ 1

Is it possible to print the address of a const declared variable?

.may I am asking the silly question.cause I am just a beginner.I encountered this .that y I posted a question here.

8th Aug 2016, 7:41 PM
Atul Anand Jha
Atul Anand Jha - avatar
8 Respostas
+ 2
Sure, just as you would do with normal variables: #include <iostream> using namespace std; int main() { const int x = 10; cout << &x; return 0; }
9th Aug 2016, 3:17 PM
James Flanders
+ 1
not sure how relevant this is but just a syntax thing here because when you see functions written as something like it MyFunc (const int &myVal). this doesn't mean that myVal has the value of the memory address but it's the reference to that int in a read only format
9th Aug 2016, 4:18 PM
destro
+ 1
yes we can print the address of the constant vale . if we have const x =5; then we print &x to print address of x value.
22nd Aug 2016, 3:13 AM
Kuldeep Kashyap
0
thanks brother, @james..it worked. but I had faced a problem regarding this few days earlier.I will post that one too for you.to explain to me. thanks again.
15th Aug 2016, 3:08 PM
Atul Anand Jha
Atul Anand Jha - avatar
0
yes
5th Nov 2016, 11:23 AM
Abdenour Sahel
Abdenour Sahel - avatar
0
ćŻä»„çš„ïŒŒäž€æ„Œæ­Łè§Ł
23rd Nov 2016, 2:29 AM
idstudio_sl
idstudio_sl - avatar
0
yes it can
15th Dec 2016, 8:52 PM
milad
0
Yes, it is possible to print its address. The restrictions with const type is you cannot change its value anywhere in program. If any function or action tries to make changes to a const type variable it will generate an error. 😀
19th Dec 2016, 5:08 AM
RSx