C++

C language variable types and output control usage examples tutorial


This article illustrates the use of C language variable types and output control, which is helpful for readers to summarize and conclude them. This example is Shared for your reference. The details are as follows:

The complete example code is as follows:


#include <stdio.h>
int main(void)
{

  int i1=024;     //The octal number begins with 0
  int i2=0xF0;    //Hexadecimal begins with 0x or 0x
  printf("[Output]n");
  printf(" Octal number 024 Is the decimal value of: t%dn",i1);
  printf(" Hexadecimal number 0xF0 Is the decimal value of: t%dn",i2);


  double f1=1E1;
  double f2=0.3E1;

  printf("n[Output]n");
  printf("%.1f/%.1f = %-10.6lf|n",f1,f2,f1/f2);   //The line "|" is used to indicate the end position


  const float PI = 3.1415926535898f;
  printf("n[Output]n");
  printf("PI is: %.7fn",PI);


  char c1='a' , c2='b' ;
  printf("n[Output]n");
  printf(" test printf() The return value of the function n");
  printf("%dn",printf("%d",printf("%c%c",c1,c2))); //The return value of the printf() function is the number of output characters


  char ch1=0; //Initialize to null
  printf("n[Output]n");
  printf("Int The type and Char Type of ASCII Coding correspondence n");
  printf("tInttCharn");
  printf("t----t----n");
  for(int i=0;i<128;i++)
  {
    ch1=i;
    printf("t%dt%cn",i,ch1);
  }
  return 0;
}

Interested readers can test out and run this article’s example, which I believe will yield new results.