Skip to content
Related Articles

Related Articles

Improve Article

C | String | Question 12

  • Difficulty Level : Medium
  • Last Updated : 28 Jun, 2021

Output of following program

Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.




#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

My Personal Notes arrow_drop_up
Recommended Articles
Page :