main()
{
int ptr[] = {1,2,23,6,5,6};
printf("%d",&ptr[3]-&ptr[0]);
}

Answers were Sorted based on User's Feedback



main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }..

Answer / sandeep

3
because aray pointer arthematic considers positions(index) of aray

Is This Answer Correct ?    46 Yes 10 No

main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }..

Answer / vivek

ans - none

Is This Answer Correct ?    18 Yes 12 No

main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }..

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

main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }..

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

main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }..

Answer / mitesh mahera

I need a answer aboutthis question..if any can ?!

Is This Answer Correct ?    4 Yes 6 No

main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }..

Answer / deveshdashora

6

Is This Answer Correct ?    6 Yes 10 No

main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }..

Answer / jithin ramakrishnan

2

Is This Answer Correct ?    0 Yes 4 No

main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }..

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

Post New Answer

More C Interview Questions

swap 2 numbers without using third variable?

0 Answers   IBS,


which one is not preprocessor directive a)#if b)#elif c)#undef d)#pragma

16 Answers   Accenture, Infosys, TCS, Wipro,


what is the output of the below code? main( ) { printf ( "\nOnly stupids use C?" ) ; display( ) ; } display( ) { printf ( "\nFools too use C!" ) ; main( ) ; }

3 Answers  


proc() { static i=10; printf("%d",i); } If this proc() is called second time, what is the output?

7 Answers   Hughes,


What is the difference between #include <header file> and #include “header file”?

0 Answers  






How can I access a memory located at certain address?

2 Answers   CSC,


typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

0 Answers  


What is the Difference between Macro and ordinary definition?

3 Answers   Bosch, Cognizant, College School Exams Tests, Motorola,


12. Look at the Code: main() { int a[]={1,2,3},i; for(i=0;i<3;i++) { printf("%d",*a); a++; } } Which Statement is/are True w.r.t the above code? I.Executes Successfully & Prints the contents of the array II.Gives the Error:Lvalue Required III.The address of the array should not be changed IV.None of the Above. A)Only I B)Only II C)II & III D)IV

4 Answers   Accenture,


write a function which accept two numbers from main() and interchange them using pointers?

3 Answers  


suppose we use switch statement and we intilize years name using enum statement like(jan,feb,mar,------dec) we take integer value as an input .question is that the month which we analyz is from 0 to 11 bt if i enter 12 than how he again starts from begning and print jan

1 Answers  


WAP to convert text into its ASCII Code and also write a function to decode the text given?

2 Answers  


Categories