StreakPeaked· Practice

ExamsGATETechnical

Consider the following C program: ```c #include <stdio.h> void stringcopy(char *, char *); int main(){ char a[30] = "@#Hello World!"; stringcopy(a, a + 2); printf("%s\n", a); return 0; } void stringcopy(char *s, char *t) { while (*t) *s++ = *t++; } ``` Which ONE of the following will be the output of the program?

  1. @#Hello World!
  2. Hello World!
  3. ello World!
  4. Hello World!!

Correct answer: ello World!

Solution

The function copies characters from `a + 2` into `a`, so the first two characters '@#' are overwritten by 'H' and 'e', and the remaining characters shift left. Because the source and destination overlap, the resulting string becomes 'ello World!'.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →