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
Stimulate calculator using Switch-case-default statement for two numbers
What is far pointer in c?
What is pragma c?
How can I list all of the predefined identifiers?
What is return type in c?
Explain function?
Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record
What is a char in c?
Sir,please help me out with the code of this question. Write an interactive C program that will encode or decode multiple lines of text. Store the encoded text within a data file, so that it can be retrieved and decoded at any time. The program should include the following features: (a) Enter text from the keyboard, encode the text and store the encoded text in a data file. (b) Retrieve the encoded text and display it in its encoded form. (c) Retrieve the encoded text, decode it and then display the decoded text. (d) End the computation. Test the program using several lines of text of your choice.
What is #pragma statements?
Why doesnt this code work?
What is scanf () in c?
How does placing some code lines between the comment symbol help in debugging the code?
Is c pass by value or reference?
How do you initialize pointer variables?