I'm working on mario trying to print hashes and spaces, but rather I get these symbols printed out instead

enter image description here.

Why am I getting these symbols?

I'm using statements like these within my program to print the hashes and spaces

char pyramid = '\0';
pyramid += '#'; // print one more #
pyramid += ' '; // print one more whitespace
pyramid += '\n'; // print a new line
printf("%c\n", pyramid); // print the pyramid

1 Answer 1


chars are really numbers underneath the hood. That means, when you add them to each others using the addition operator (i.e., +), you're really adding their ASCII values.

There are some unprintable chars in the ASCII table. In addition to that, a char variable might take a value only in range [-128, 127]. The ASCII characters have values in range [0, 127] and the printable characters have values in range [32, 126].

If you tried to print any unprintable character or an invalid value as a char, you'll probably get these symbols printed instead.

You may have a look at this answer to get some sort of an idea about how you should solve mario!

  • You actually gave me the answer. Thanks.
    – iCS50
    Jul 15, 2014 at 1:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .