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 |
What is main () in c language?
write a c program to print "Welcome" without using semicolon in the whole program ??
Please write me a program to print the first 50 prime numbers (NOT between the range 1 -50)
Write a c program to demonstrate Type casting in c?
hi any body pls give me company name interview conduct "c" language only
What are the two types of functions in c?
What is a wrapper function in c?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
What is the use of clrscr?
What are the 4 types of functions?
what is develop in c language
How to define structures? ·