1

I tried printf(n, " is equal to " x, /n); But it didn't work. How do I make it print the value of n (a variable ), then a space after it then "is equal to " then the value of x.

2

That depends on the type of the variable:

As a example forn an integer (int):

int n = 25;

printf("n is equal to %d\n", n); 

The %d is a placeholder for an integer, when the message inside the double cuotes is printed the %d is replaced by the actual value of the variable that is passed as argument after the coma.

Other example with an integer and a string:

int age = 25;
char name[] = "John Doe";

printf("%s has %d years\n", name, age);

This should print:

John Doe has 25 years

Here %s is a placeholder for a string and %d for an int, the variables must be separated with comas and in the same order that apear inside the double cuotes.

Here you can find more about placeholders: http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output

You must log in to answer this question.

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