Very much a beginner to C, in fact this is my first tester program.
I can't actually figure out how to print this number out to the terminal.
#include <stdio.h> int addNumbers(int a, int b) { int sum = a + b; return sum; } int main(void) { int a = 4; int b = 7; printf(addNumbers(a,b)); return 0; }
I am sure that in Java I could just replace the printf
with System.out
and it would have worked. I tried searching the answer earlier but if you don't know what to search it's hard to find an answer.
%d tells printf that the corresponding argument is to be treated as an integer value; the type of the corresponding argument must be int .
The C language does not provide an inbuilt data type for strings but it has an access specifier “%s” which can be used to directly print and read strings.
Print Function in C, C++, and Python Print function is used to display content on the screen. Approach: Some characters are stored in integer value inside printf function. Printing the value as well as the count of the characters.
printf (print formatted) in C, writes out a cstring to stdout (standard output). The provided cstring may contain format specifiers( beginning with % in the cstring). If there are format specifiers, those are replaced with their respective arguments that follow the cstring to the printf call.
try this:
printf("%d", addNumber(a,b))
Here's the documentation for printf.
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