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

print ur name without using any semicolon in c/c++....

21 Answers   Bosch, TCS, Wipro,


write an algorithm to get a sentence and reverse it in the following format: input : I am here opuput: Here Am I note: first letter of every word is capiatlised

3 Answers  


Difference between Function to pointer and pointer to function

0 Answers  


What is the use of a semicolon (;) at the end of every program statement?

1 Answers  


how to use virual function in real time example

1 Answers   CTS, Wipro,






Differentiate between calloc and malloc.

0 Answers   Wipro,


What are the types of variables in c?

0 Answers  


If I want to initialize the array like. int a[5] = {0}; then it gives me all element 0. but if i give int a[5] = {5}; then 5 0 0 0 0 is ans. what will I do for all element 5 5 5 5 5 in a single statement???

3 Answers   Amdocs, IBM,


please can some one guide me, to the answer Write a C program to enter 15 numbers as an input from the keyboard and program will find and print odd numbers and their average. i have studied while and do while loop for loop if and else if switch

2 Answers  


How can I access memory located at a certain address?

3 Answers   Verizon,


# define prod(a,b)=a*b main() { int x=2; int y=3; printf("%d",prod(x+2,y-10)); } the output of the program is a.8 b.6 c.7 d.none

7 Answers   Microsoft, TCS,


Explain what are multibyte characters?

0 Answers  


Categories