#include <stdio.h>
char char1; /* first character */
char char2; /* second character */
char char3; /* third character */
main()
{
char1 = 'A';
char2 = 'B';
char3 = 'C';
(void)printf("%c%c%c reversed is %c%c%c\n",
char1, char2, char3,
char3, char2, char1);
return (0);
}
Why we use void with the printf function? what are use of void with the printf function?
printf returns a value which most people don't use most of the time. Some tools (e.g. 'lint') warn about this unused return value, and a common way of suppressing this warning is to add the (void) cast.
It does nothing in terms of execution, it's just a way of telling your tools that you know that you're happy to ignore the return value.
That looks like very old C
code.
The (void)
cast before printf
is used to signify that you're ignoring printf
's return value. It's not necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With