main()
{
int *ptr=(int*)malloc(sizeof(int));
*ptr=4;
printf("%d",(*ptr)+++*ptr++);
}

Answers were Sorted based on User's Feedback



main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }..

Answer / 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

main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }..

Answer / abhishek

(*ptr)++ = 5
(*ptr)++ = 5
(*ptr)+++(*ptr)++ = 5 + 5 = 10

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Interview Questions

Are there constructors in c?

0 Answers  


Explain enumerated types.

0 Answers  


Do you have any idea about the use of "auto" keyword?

0 Answers  


wtite a program that will multiply two integers in recursion function

4 Answers   TCS,


What is the use of extern in c?

0 Answers  






What is pivot in c?

0 Answers  


What are the keywords in c?

0 Answers  


write a code for large nos multilication (upto 200 digits)

2 Answers   Persistent,


How does struct work in c?

0 Answers  


Why doesn't C support function overloading?

2 Answers  


What does node * mean?

0 Answers  


Add Two Numbers Without Using the Addition Operator

0 Answers  


Categories