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 do you mean by c?

580


What is the use of a ‘’ character?

580


Why is c called c not d or e?

602


What Is The Difference Between Null And Void Pointer?

636


What is external variable in c?

605






Explain the use of bit fieild.

702


Explain the difference between malloc() and calloc() function?

594


What is wild pointer in c with example?

568


What is the difference between mpi and openmp?

727


What is 1f in c?

1827


‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .

2366


Can you mix old-style and new-style function syntax?

658


What are different types of pointers?

558


difference between native and cross compilers

1667


Explain what is a program flowchart and explain how does it help in writing a program?

643