Top

Discussion

Point out the error of the following code −

#include 
#include 
#include 
int main() {
   char* ptr;
   *ptr = (int*)malloc(30);
   strcpy(ptr, "ABC");
   printf("%s", ptr);
   free(ptr);
}

 

  • A.Error in strcpy() statement
  • B.Error in *ptr = (int*)malloc(30);
  • C.Error in free(ptr)
  • D.No Error

Answer: B

Here this makes integer from pointer, without a cast

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

Post your comment