main()
{
int *ptr=(int*)malloc(sizeof(int));
*ptr=4;
printf("%d",(*ptr)+++*ptr++);
}
Answers were Sorted based on User's Feedback
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 |
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 |
Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??
void main() { int i=5; printf("%d",i++ + ++i); }
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }
x=2 y=3 z=2 x++ + y++; printf("%d%d" x,y);
void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”); }
main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }
main() { int i =10, j = 20; clrscr(); printf("%d, %d, ", j-- , --i); printf("%d, %d ", j++ , ++i); } a. 20, 10, 20, 10 b. 20, 9, 20, 10 c. 20, 9, 19, 10 d. 19, 9, 20, 10
void main() { int i; char a[]="\0"; if(printf("%s\n",a)) printf("Ok here \n"); else printf("Forget it\n"); }
how to return a multiple value from a function?
main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }
Finding a number multiplication of 8 with out using arithmetic operator
main() { int *j; { int i=10; j=&i; } printf("%d",*j); }