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


Please Help Members By Posting Answers For Below Questions

a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

640


What are the advantages of external class?

590


Explain what will the preprocessor do for a program?

593


Why c is called a middle level language?

634


Can static variables be declared in a header file?

612






what is the height of tree if leaf node is at level 3. please explain

1593


How do I get a null pointer in my programs?

614


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.

1475


What is the difference between local variable and global variable in c?

682


Compare interpreters and compilers.

634


What is the size of array float a(10)?

651


Explain what is the general form of a c program?

618


Differentiate Source Codes from Object Codes

813


Why do we use namespace feature?

577


Are the variables argc and argv are always local to main?

569