main()
{
int ptr[] = {1,2,23,6,5,6};
printf("%d",&ptr[3]-&ptr[0]);
}
Answers were Sorted based on User's Feedback
Answer / sandeep
3
because aray pointer arthematic considers positions(index) of aray
| Is This Answer Correct ? | 46 Yes | 10 No |
Answer / shivam jindal
That should print a 3. It's really the same as
printf("%d", 3-0);
...since:
ptr[3] is the 4th element in the ptr[] array.
&ptr[3] is a pointer to the 4th element in the ptr[] array.
&ptr[0] is similarly a pointer to the first element in ptr[].
&ptr[3] - &ptr[0] is a subtraction of two pointers. That's only defined (in standard C/C++) for pointers to elements in the same array, like in this case, and it's defined as the difference between the index values. That's where the 3-0 comes from.
The result of a pointer difference is an int. &ptr[0] - &ptr[3] results in 0-3 which is -3.
| Is This Answer Correct ? | 5 Yes | 3 No |
Answer / dipak
In int at least 2 bytes are used for size and we know that &ptr[] gives the address of ptr .
&ptr[3]-&ptr[0]
Size of &ptr[3] is 3*2=6 times greater than Size of &ptr[0] is 1*2=2
ptr[0] also have any value that's why I consider it 1
So 6-2=4
| Is This Answer Correct ? | 4 Yes | 3 No |
Answer / mitesh mahera
I need a answer aboutthis question..if any can ?!
| Is This Answer Correct ? | 4 Yes | 6 No |
Answer / baba
Ans: 12
The expression in printf evaluates the difference of the memory addresses of ptr[3] and ptr[0]
| Is This Answer Correct ? | 5 Yes | 10 No |
what is meant by the "equivalence of pointers and arrays" in C?
what is the use of using linked list and array?
I have a function which accepts, and is supposed to initialize,a pointer, but the pointer in the caller remains unchanged.
Which command is more efficient? *(ptr+1) or ptr[1]
i=10,j=20 j=i,j?(i,j)?i:j:j print i,j
What does the function toupper() do?
How can I set an array's size at run time?
show how link list can be used to repersent the following polynomial i) 5x+2
What is nested structure in c?
Why calloc is better than malloc?
what is the significance of static storage class specifier?
what is the difference between declaration ,defenetion and initialization of a variable?