main()
{
int *ptr=(int*)malloc(sizeof(int));
*ptr=4;
printf("%d",(*ptr)+++*ptr++);
}
Answer Posted / c.p.senthil
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 |
Post New Answer View All Answers
Why doesnt that code work?
What is structure and union in c?
This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory
What are disadvantages of C language.
What is context in c?
What is return type in c?
What is the use of c language in real life?
What is const and volatile in c?
Whats s or c mean?
Ow can I insert or delete a line (or record) in the middle of a file?
What is the easiest sorting method to use?
What is difference between function overloading and operator overloading?
Write a code to remove duplicates in a string.
What is "Hungarian Notation"?
What does 3 periods mean in texting?