logo

Crowdly

Consider the following code fragment: char str[] = "ComputerGraphics"; char *p...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Consider the following code fragment:

char str[] = "ComputerGraphics";

char *p = str + 5, ch = --*p;

printf("%c,%s", ch, str);

If the code fragment cannot be compiled, write [for compile-time error]. If the code fragment's execution causes undefined behavior, write [for undefined behavior]. Otherwise, write the exact text printed to standard output stream by the code fragment.

Brief side-note on undefined behavior: The C standard says that statements such as c = (b = a + 2) - (a = 1); and c = (b = a + 2) - (a = 1); cause undefined behavior [because we don't know whether the left or right operand of operator - is evaluated first]. When a program ventures into the realm of undefined behavior, all bets are off. The program may behave differently when compiled with different compilers. But that's not the only thing that can happen. The program may not compile in the first place, if it compiles it may not run, and if it does run, it may crash, behave erratically, or produce meaningless results. In other words, undefined behavior should be avoided like the plague.

More questions like this

Want instant access to all verified answers on distance3.sg.digipen.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!