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

What is pragma c?

0 Answers  


i=20,k=0; for(j=1;j<i;j=1+4*(i/j)) { k+=j<10?4:3; } printf("%d", k);

8 Answers   HCL,


difference between the array and linked list general difference related to memory

2 Answers  


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.

0 Answers   IBM,


In CMM or CMMI certified organizations,we assess only the standard software processes of the organization. We do not assess the organizations other functional departments like HR or Admin. Then how can we certify the entire organization as CMM level company?? We have assessed only software related activities. Right. There is no relation with other departments like Accounts, HR or Admin. Then how can we claim that the whole company is a CMM certified company?

1 Answers   Melstar,






What is wrong in this statement? scanf(“%d”,whatnumber);

0 Answers  


What is data type long in c?

0 Answers  


what is data structure

5 Answers   Maveric, TCS,


Are the expressions * ptr ++ and ++ * ptr same?

0 Answers  


What are the two types of structure?

0 Answers  


What is the exact difference between '\0' and ""

3 Answers  


a.One Cannot Take the address of a Bit Field b.bit fields cannot be arrayed c.Bit-Fields are machine Dependant d.Bit-fields cannot be declared as static Which of the Following Statements are true w.r.t Bit-Fields A)a,b&c B)Only a & b C)Only c D)All

3 Answers   Accenture, Digg.com,


Categories