Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

How can I copy just a portion of a string?

0 Answers  


write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1

0 Answers  


Explain what are linked list?

0 Answers  


how to find the largest element of array without using relational operater?

6 Answers   Satyam, Wipro,


What is the best way of making my program efficient?

0 Answers  


What does the c preprocessor do?

0 Answers  


let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................

8 Answers  


what are the files which are automatically opened when a c file is executed?

3 Answers  


what is the difference between : func (int list[], ...) or func (int *list , ....) - what is the difference if list is an array and if also if list is a pointer

2 Answers  


What is the difference between array and linked list in c?

0 Answers  


c programming of binary addition of two binary numbers

4 Answers  


write a program to swap two numbers without using temporary variable?

3 Answers  


Categories