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 is main function so important?
What is huge pointer in c?
how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?
hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel
Explain how can I remove the trailing spaces from a string?
What is the use of bitwise operator?
How can I read data from data files with particular formats?
What is sizeof in c?
Is there any demerits of using pointer?
Write the test cases for checking a variable having value in range -10.0 to +10.0?
Why c is called a middle level language?
Calculate 1*2*3*____*n using recursive function??
What is include directive in c?
What are the 4 types of programming language?
Is c is a low level language?