C | String | Question 12

Output of following program

filter_none

edit
close

play_arrow

link
brightness_4
code

#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;
}

chevron_right


(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



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.