aliensbrain
  • Home
  • Study
  • Quizzes
  • 🎤AI Practicefree
  • Notebooks
  • Community
  • Sign in
  • C Programming Fundamentals
  • char ptr1[] = "Hello World"; char *ptr2 = malloc( 5 ); pt...
Multiple choice

char ptr1[] = "Hello World"; char *ptr2 = malloc( 5 ); ptr2 = ptr1; What is wrong with the above code (assuming the call to malloc does not fail)?

  1. There will be a memory overwrite.

  2. There will be a memory leak.

  3. There will be a segmentation fault.

  4. Not enough space is allocated by the malloc.

  5. It will not compile.

Reveal answer Fill a bubble to check yourself
A Correct answer

Keep practicing — related questions

  • What is wrong with the following code? int * x = (int *) malloc(100 * sizeof(int)); x = realloc(x, sizeof(i...
  • The following statement would allocate memory on? char *ptr = malloc(10);
  • void main() { int *ptr; int item=5; int arr[]={10,20,30,40,50}; ptr = &item; for(;item>=0;item--) { printf(...
  • Code: char *ptr; char myString[] = "abcdefg"; ptr = myString; ptr += 5; What string does ptr point to in th...
  • What the following program is executed? void main() { void *ptr = (void*) malloc(sizeof(void)); ptr++ ; }
  • char *ptr; char myString[] = abcdefg; ptr = myString; ptr += 5; What string does ptr point to in the sample...
  • 2.What will print out? main() { char *p1=“name”; char *p2; p2=(char*)malloc(20); memset (p2, 0, 20); while(...
  • What will be the output of the following: void main() { char const *ptr="abc"; ptr="xyz"; printf("%s",ptr); }
Play the full quiz 🎤 Practise this topic out loud
Advertisement
© Aliensbrain | all rights reserved
  • About
  • Contact
  • Terms and Condition
  • Privacy Policy