+ 2
What output is this?
This below code output the address. But I don't know,this address belongs to which? I mean,it belongs to a[0] index alone || it belongs to total indices in int a[ ] ? https://code.sololearn.com/c13jzRhG8KRl/?ref=app
6 Respostas
+ 4
You decleared array which type is int and it can store 5 integer becoz you wrote size 5 . It will be better to write like this when u defining multiple elements
int a[ ]= {22,33,44,55,66}; here you dont need to declear size of array it will take automatically according to your elements.
In next line you decleared pointer ptr which will point int type values .
In next line u wrote
ptr =&a[0] ; here a[0] representing the first index of array address if u will print first value 22 then
& a[0] it will print address . If u write &a[1] then it will print the address of next element .
You asking how to print address of all elements then you can write in loop or u can write single single statements .
I used loop
#include <stdio.h>
int main() {
int a[ ] = {22, 33, 44, 55, 66};
int *ptr = NULL;
for(int i=0;i<5;i++)
{
ptr = &a[i];
printf("\n%p",ptr);
}
}
+ 3
Thank you codemonkey 😊
+ 2
codemonkey then how can find the address of whole array.?
can I able to find it?
i.e int a[5]
+ 2
codemonkey you mean address of array (i.e int a[ ])
Is same for first array element address (i.e a[0])
Am I right ?
if yes means,can you give me reason for that.....
+ 2
Thank you so much codemonkey 😁
+ 1
Thank you ♨️TEJAS MK-82♨️ 😊