Multiple choice technology programming languages

What will print out? main() { char p1=“name”; char *p2; p2=(char)malloc(20); memset (p2, 0, 20); while(*p2++ = *p1++); printf(“%sn”,p2); }

  1. empty string

  2. 20

  3. 0

  4. error

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The code copies string 'name' to dynamically allocated memory with memset. However, the while loop increments p2 after copying the null terminator. After copying ends, p2 points to the null terminator byte, not the start of the copied string. When printf prints from p2, it prints an empty string since p2 now points to the null character.