Search⌘ K
AI Features

Time to Pull Out Your Hair

Explore a coding puzzle that challenges your understanding of C programming logic and output prediction. Learn to analyze code carefully and improve your problem-solving skills in C through practical examples.

We'll cover the following...

Puzzle code

Read carefully the code given below:

C
#include <stdio.h>
void modify(char *c)
{
*(c+1) = 'o';
}
int main()
{
char *string = "cat";
printf("Before: %s\n", string);
modify(string);
printf("After: %s\n", string);
return(0);
}

Your task: Guess the output

Attempt the following test to assess your understanding.

Technical Quiz
1.

What is the expected output of the above code?

A.
Before: cat
After: cot
B.
Before: cat
After: oat
C.
Before: cat
After: cat
D.
Before: cat
Segmentation fault (core dumped)

1 / 1

Let's discuss the code and output together in the next lesson.