Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print in C

Tags:

c

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.

like image 465
sbsp Avatar asked Jan 29 '10 15:01

sbsp


People also ask

What is %d in printf in C?

%d tells printf that the corresponding argument is to be treated as an integer value; the type of the corresponding argument must be int .

What is %s in C?

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.

What is the use of print in C?

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.

Can you write printf in C?

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.


1 Answers

try this:

printf("%d", addNumber(a,b)) 

Here's the documentation for printf.

like image 110
nickf Avatar answered Oct 05 '22 14:10

nickf