C | String | Question 12
Output of following program
#include <stdio.h>int fun(char *p){ if (p == NULL || *p == '\0') return 0; int current = 1, i = 1; while (*(p+current)) { if (p[current] != p[current-1]) { p[i] = p[current]; i++; } current++; } *(p+i)='\0'; return i;} int main(){ char str[] = "geeksskeeg"; fun(str); puts(str); return 0;} |
(A) gekskeg
(B) geeksskeeg
(C) geeks
(D) Garbage Values
Answer: (A)
Explanation: The function mainly replaces more than once consecutive occurrences of a character with one one occurrence.
Quiz of this Question
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.



