Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Printf Practice | Data
C Basics

book
Printf Practice

Example: Using Format Specifiers and Variables in Printing

c

main

copy
#include <stdio.h>

int main()
{
int iVariable = 832;
float fVariable = 54.984;
char cVariable = '#';

printf(" iVariable = %d \n fvariable = %f \n cVariable = %c \n", iVariable, fVariable, cVariable);

return 0;
}
123456789101112
#include <stdio.h> int main() { int iVariable = 832; float fVariable = 54.984; char cVariable = '#'; printf(" iVariable = %d \n fvariable = %f \n cVariable = %c \n", iVariable, fVariable, cVariable); return 0; }
Task

Swipe to start coding

  • Assign the value of 100 to the variable named intVariable.
  • Choose an appropriate data type for the variable charVariable.
  • Utilize the printf() function to display the values of both variables in a single call.

Once you've completed this task, click the button below the code to check your solution.

Solution

#include "stdio.h"

int main()
{
int intVariable = 100;
char charVariable = '$';

printf("%d %c", intVariable, charVariable);

return 0;
}

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 8
#include "stdio.h"

int main()
{
int intVariable = ___;
___ charVariable = '$';

printf("___", intVariable, charVariable);

return 0;
}
toggle bottom row
some-alt