Search⌘ K
AI Features

Whoa! Hold on There

Understand how to analyze programming puzzles in C by carefully reading code and predicting outputs. This lesson helps you develop critical thinking and assess your understanding of core C concepts through hands-on exercises.

We'll cover the following...

Puzzle code

Read carefully the code given below:

C++
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int array[5];
int x;
srand( (unsigned)time(NULL) );
for( x=0; x<12; x++ ) {
array[x] = rand() % 100;
printf(" %d", array[x]);
}
putchar('\n');
return(0);
}

Your task: Guess the output

Attempt the following test to assess your understanding.

Technical Quiz
1.

What will be the output of the following code?

A.

The code outputs 12 random numbers between 0 and 99.

B.

The code outputs 5 random numbers between 0 and 99.

C.

The code outputs 12 random numbers but may detect a stack smashing.

D.

The code will not compile due to an error.


1 / 1

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