0
How to find memory address of a variable in c
like if mark is an array .To find its memory location we can find it by printf("%d",mark); how to find it for a variable in c language
5 odpowiedzi
+ 1
I'm guessing that you want to print the address of the array. Instead of %d which is uses for decimal numbers you would use %p for pointer addresses. It should look like this:
printf("%p", mark);
@VEdward From what I know, there isn't any std::cout in C rather than C++.
+ 1
int x = 5; // created int variable and set to 5
int *ptr = &x; //created a pointer of int type, pointing to the address of variable x.
printf("%p",ptr); // printing the address of variable x.
// ptr holds the address of x, not the value of x which is 5.
// if x was an array you would just use x because the name of an array is actually a pointer.
printf("%p",x);
0
by using ampersand (&)
int number = 5;
cout << &number ;
this will give you memory location of number variable
0
if mark is an array, then
mark is a "shortcut" for &mark[0]
so:
mark
mark + 0
&mark[0]
are the same thing, the address of the first element.
0
well @R-ry you can use whatever it has.. xD if it has printf() use printf() if put() then use put() or print()
xD