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
Can we change the value of constant variable in c?
When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.
How to get string length of given string in c?
What does 1f stand for?
What is graph in c?
What is the use of bit field?
Is c weakly typed?
How is null defined in c?
Describe the modifier in c?
A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none
Explain data types & how many data types supported by c?
What is volatile variable in c with example?
How can a number be converted to a string?
How are portions of a program disabled in demo versions?
What is a stream in c programming?