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
In a byte, what is the maximum decimal number that you can accommodate?
What are void pointers in c?
What is a sequential access file?
Can true be a variable name in c?
What are the preprocessor categories?
What 'lex' does?
How is actual parameter different from the formal parameter?
Explain what is the difference between far and near ?
Does sprintf put null character?
Why is it important to memset a variable, immediately after allocating memory to it ?
Can a pointer be volatile in c?
What is a class c rental property?
What is linear search?
What is volatile, register definition in C
Why functions are used in c?