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 / john lee

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

Like above, code should be revised as allocated memory space just has 2(16bit machine) or 4 byte(32bit machine) to save '4'.
If not, the orginal code, printf("%d",(*ptr)++ + *ptr++);

In my guess, ptr++ will be first, and then *ptr would be next.
If so, ptr++ will point to a memory address unintended(an address +2 or +4 added). And then *ptr will have a value like 0 or else.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / ram

error due to constant can't be increment

Is This Answer Correct ?    0 Yes 0 No

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

Answer / vinod

Answer = 8
Explanation:
*ptr=4;
printf("%d",(*ptr)+++*ptr++);
The above statement can be interpreted as (*ptr)++ + *ptr++
(*ptr)++ - Post increment the Value pointer by ptr i.3. 4
*ptr++ - Return the value of ptr and increment the position of ptr i.e. 4
So (*ptr)++ + *ptr++ => 4 + 4 => 8

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More C Code Interview Questions

how to check whether a linked list is circular.

11 Answers   Microsoft,


respected sir, i did my MCA in 2013 when i am going to attend to an interview i was asked about my project how will i explain my project could please help me in this and my project title is "Social Networking Site For Social Responsibility"

1 Answers   Genpact, Ozdocs,


can u give me the c codings for converting a string into the hexa decimal form......

1 Answers  


Write a program using one dimensional array to assign values and then display it on the screen. Use the formula a[i]=i*10 to assign value to an element.

1 Answers   Samar State University,


What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

1 Answers  






main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above

3 Answers   HCL,


int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }

2 Answers   CSC,


Write a C program to print ‘Campus Force training’ without using even a single semicolon in the program.

3 Answers   Wipro,


Give a oneline C expression to test whether a number is a power of 2?

25 Answers   EA Electronic Arts, Google, Motorola,


main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }

2 Answers   Adobe, CSC,


main() { char c; int i = 456; clrscr(); c = i; printf("%d", c); } a. 456 b. -456 c. random number d. none of the above

3 Answers   BrickRed, HCL,


main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }

2 Answers  


Categories