main()
{
int *ptr=(int*)malloc(sizeof(int));
*ptr=4;
printf("%d",(*ptr)+++*ptr++);
}
Answers were Sorted based on User's Feedback
Ans = 8
Explanation:
after brackets post increment has higher precedence,
hence expression can be viewed as
(*ptr)++ + *ptr++
printf("%d",(*ptr)+++*ptr++); can be expanded in 3 steps as
1. printf("%d",(*ptr)+*ptr); => displays 4+4
2. ptr++; => increments the pointer to next location
3. (*ptr)++; => increments the value in that location
This program can be better understood, with the below modification
main()
{
int *ptr=(int*)malloc(sizeof(int)*2);
*ptr=4; // current location value = 4
*(ptr+1) = 10; // next location value = 10
printf("%d\n",(*ptr)+++*ptr++); // display 8 (4+4)
printf("%d\n",*(ptr-1)); // current location value = 4
printf("%d\n",*ptr); // next location value = 10+1 = 11
}
Is This Answer Correct ? | 3 Yes | 3 No |
Answer / abhishek
(*ptr)++ = 5
(*ptr)++ = 5
(*ptr)+++(*ptr)++ = 5 + 5 = 10
Is This Answer Correct ? | 0 Yes | 2 No |
Are there constructors in c?
Explain enumerated types.
Do you have any idea about the use of "auto" keyword?
wtite a program that will multiply two integers in recursion function
What is the use of extern in c?
What is pivot in c?
What are the keywords in c?
write a code for large nos multilication (upto 200 digits)
How does struct work in c?
Why doesn't C support function overloading?
What does node * mean?
Add Two Numbers Without Using the Addition Operator