C Programming - Arrays - Discussion
Discussion Forum : Arrays - Find Output of Program (Q.No. 9)
9.
What will be the output of the program if the array begins at address 65486?
#include<stdio.h>
int main()
{
int arr[] = {12, 14, 15, 23, 45};
printf("%u, %u\n", arr, &arr);
return 0;
}
Answer: Option
Explanation:
Step 1: int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and initialized.
Step 2: printf("%u, %u\n", arr, &arr); Here,
The base address of the array is 65486.
=> arr, &arr is pointing to the base address of the array arr.
Hence the output of the program is 65486, 65486
Discussion:
17 comments Page 1 of 2.
Karthik said:
1 decade ago
Can anyone explain it briefly?
Rupinderjit said:
1 decade ago
In this case arr and &arr is the same thing. So obviously both points to same address.And as we see the available options, option B is relevant. So do the answer.
%u format specifier is used to print the unsigned value.And we know that address of am any cell of the memory can't be negative(that is, can't be of signed value).
Hope u'll get this.
%u format specifier is used to print the unsigned value.And we know that address of am any cell of the memory can't be negative(that is, can't be of signed value).
Hope u'll get this.
Saurabh Pandey said:
1 decade ago
Why both arr and &arr are same??
arr contains the address of the first element of the array. ie;
arr = &arr[0]
so &arr should be &(&arr).ie;
&arr = &(&arr)
It means both are different. Can any one explain whether they are different or same? If same, how??
arr contains the address of the first element of the array. ie;
arr = &arr[0]
so &arr should be &(&arr).ie;
&arr = &(&arr)
It means both are different. Can any one explain whether they are different or same? If same, how??
Manideep said:
1 decade ago
Yeah, arr=&arr[0]
That is arr stores address of frst element in array (i.e base addres of array) and &arr also gives base address.
If I am wrong Let me Know :)
That is arr stores address of frst element in array (i.e base addres of array) and &arr also gives base address.
If I am wrong Let me Know :)
Shibu said:
1 decade ago
Can anyone explain me the difference between
printf ("%u, %u\n", arr, &arr) ;
and
printf ("%u, %u\n", a+1, &a+1) ;
Please follow question 6 and 9.
printf ("%u, %u\n", arr, &arr) ;
and
printf ("%u, %u\n", a+1, &a+1) ;
Please follow question 6 and 9.
Sanjoy said:
1 decade ago
int arr[] = {12, 14, 15, 23, 45};
If we write arr we get the base address.
&arr gives the base address of the 1st element(12).
We know arr[0]=*(arr+0).
&arr[0]=&(*(arr))=arr.
So both are equal.
If we write arr we get the base address.
&arr gives the base address of the 1st element(12).
We know arr[0]=*(arr+0).
&arr[0]=&(*(arr))=arr.
So both are equal.
Urvashi said:
10 years ago
#include<stdio.h>
int main()
{
int arr[] = {12, 14, 15, 23, 45};
printf("%u, %u\n", arr+1, &arr+1);
return 0;
}
What would be the answer?
int main()
{
int arr[] = {12, 14, 15, 23, 45};
printf("%u, %u\n", arr+1, &arr+1);
return 0;
}
What would be the answer?
Kundan singh said:
10 years ago
Arr gives the base address and here arr+1 means it gives the address of 2nd element. Here 1 denotes we are adding 2 byte to the base address.
And &arr+1 gives the address of next array of 5 integers means it will gives the address of last integers.
And &arr+1 gives the address of next array of 5 integers means it will gives the address of last integers.
Puneet said:
10 years ago
&arr+1 = Base address+5*size of (int).
Krutika said:
9 years ago
In simpler terms, the starting address of an array is equal to the starting address of the first element in an array.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers