main()
{
int ptr[] = {1,2,23,6,5,6};
printf("%d",&ptr[3]-&ptr[0]);
}
Answers were Sorted based on User's Feedback
Answer / sandeep
3
because aray pointer arthematic considers positions(index) of aray
Is This Answer Correct ? | 46 Yes | 10 No |
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 |
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 |
Answer / mitesh mahera
I need a answer aboutthis question..if any can ?!
Is This Answer Correct ? | 4 Yes | 6 No |
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 |
1. What is the output of printf("%d") 2. What will happen if I say delete this 3. Difference between "C structure" and "C++ structure". 4. Diffrence between a "assignment operator" and a "copy constructor" 5. What is the difference between "overloading" and "overridding"? 6. Explain the need for "Virtual Destructor". 7. Can we have "Virtual Constructors"? 8. What are the different types of polymorphism? 9. What are Virtual Functions? How to implement virtual functions in "C" 10. What are the different types of Storage classes? 11. What is Namespace? 12. What are the types of STL containers?. 13. Difference between "vector" and "array"? 14. How to write a program such that it will delete itself after exectution? 15. Can we generate a C++ source code from the binary file? 16. What are inline functions? 17. Talk sometiming about profiling? 18. How many lines of code you have written for a single program? 19. What is "strstream" ? 20. How to write Multithreaded applications using C++? 21. Explain "passing by value", "passing by pointer" and "passing by reference" 22. Write any small program that will compile in "C" but not in "C++" 23. Have you heard of "mutable" keyword? 24. What is a "RTTI"? 25. Is there something that I can do in C and not in C++? 26. Why preincrement operator is faster than postincrement? 27. What is the difference between "calloc" and "malloc"? 28. What will happen if I allocate memory using "new" and free it using "free" or allocate sing "calloc" and free it using "delete"? 29. What is Memory Alignment? 30. Explain working of printf. 31. Difference between "printf" and "sprintf". 32. What is "map" in STL? 33. When shall I use Multiple Inheritance? 34. What are the techniques you use for debugging? 35. How to reduce a final size of executable? 36. Give 2 examples of a code optimization.
Differentiate call by value and call by reference?
program for comparing 2 strings without strcmp()
i have a written test for microland please give me test pattern
How can I read/write structures from/to data files?
What are near, far and huge pointers?
0 Answers Hexaware, Thomson Reuters, Virtusa,
What does the error 'Null Pointer Assignment' mean and what causes this error?
write a program to swap two numbers without using temporary variable?
what is diff between localstatic and globalstatis variable possible 2 use in another file...?
What is the difference between scanf and fscanf?
What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25
Why is c still so popular?