Instructions
This exercise is for anyone who would like to get better in C/C++ coding.
I've provided some sample code, that has some problem with it. (At least one, that I wanted to focus on in this exercise, but accidentally I could have made multiple mistakes. XD)
Let's see who finds the problem.
Please, tell me
- what part of the code has a problem
- why it is a problem
- how would you fix it
The Code (with a problem):
#include <stdio.h>
void printNumber(const int * pNumber)
{
printf("%d\n", *pNumber);
}
int main()
{
short int number = 123;
printNumber((int*)&number);
return 0;
}
Update
We have a solution! See xDELLx's answer below. Thanks for finding the problem in the code.
Also, thank you for everyone for participating in this little challenge.
Good job! :)