+ 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.
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;
}
+ 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
+ 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.
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.
0
yes
0
ćŻä»„çïŒäžæ„ŒæŁè§Ł
0
yes it can
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.
đ