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 2 of 2.
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?
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.
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.
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 :)
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??
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.
Karthik said:
1 decade ago
Can anyone explain it briefly?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers