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 is define c?

574


p*=(++q)++*--p when p=q=1 while(q<=6)

1266


How do I get a null pointer in my programs?

620


What is the g value paradox?

645


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

770






What are actual arguments?

647


How to set file pointer to beginning c?

666


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

3501


What does 3 periods mean in texting?

600


How can I discover how many arguments a function was actually called with?

632


Explain what is the difference between null and nul?

657


What is pointer and structure in c?

574


What is include directive in c?

644


How can I send mail from within a c program?

581


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

631