Sizing Up Some Characters

Test your C++ programming skills by solving the given puzzle about array size determination and function parameter behavior.

Puzzle code

Carefully read the code given below:

Press + to interact
#include <iostream>
void serialize(char characters[])
{
std::cout << sizeof(characters) << "\n";
}
int main()
{
char characters[] = {'a', 'b', 'c'};
std::cout << sizeof(characters) << "\n";
std::cout << sizeof(characters) / sizeof(characters[0]) << "\n";
serialize(characters);
}

Your task: Guess the output

Try to guess the output of the above code. Attempt the following test to assess your understanding.

The possible console output lines are given below on the right side column. Place them in the correct sequence.

Drag and drop the cards in the blank spaces.


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

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.