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


Please Help Members By Posting Answers For Below Questions

What are enumerated types?

649


What are the types of unary operators?

656


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

642


Which one would you prefer - a macro or a function?

598


When should volatile modifier be used?

551






How can you avoid including a header more than once?

561


What is && in c programming?

674


There seem to be a few missing operators ..

614


What are the advantages of external class?

590


What are the data types present in c?

623


Explain continue keyword in c

579


What is volatile, register definition in C

682


FILE PROGRAMMING

1773


What is optimization in c?

562


the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

562