main()
{
int ptr[] = {1,2,23,6,5,6};
printf("%d",&ptr[3]-&ptr[0]);
}
Answer Posted / 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 |
Post New Answer View All Answers
Explain the red-black trees?
What is the meaning of 2d in c?
What is non linear data structure in c?
What is the meaning of && in c?
What is the use of header?
Write the control statements in C language
write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3
Explain high-order and low-order bytes.
Explain what are the different data types in c?
What is the purpose of the preprocessor directive error?
What will the preprocessor do for a program?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
Why do we need volatile in c?
What are conditional operators in C?
What are the disadvantages of external storage class?