Machine-translated by Google. Questions are authored in English.
Top

Discussion

Will the following program give any warning on compilation in TurboC (under DOS)?

#include <stdio.h>

int main()
{
    int *p1, i=25;
    void *p2;
    p1=&i;
    p2=&i;
    p1=p2;
    p2=p1;
    return 0;
}

 

  • A.Yes
  • B.No

Answer: B

Correct answer: No

All four assignments are legal without a cast. C converts implicitly in both directions between void * and any object pointer type, so assigning an int * to a void * and back again raises no diagnostic. It is C++ that requires an explicit cast when converting away from void *, and mixing up the two languages is what makes this question look harder than it is.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.