C-INPUT AND OUTPUT FUNCTIONS

 1. C-Output [print text].

printf() function is used to print the output or display the output.

Example:

#include <stdio.h>  //Header file
int main() //Main function 
{
  printf("Hello World!");//Output statement
  return 0;
}

Output:
Hello World!

2. C-Input [Get text].

scanf() function is used to get input from the user.

Example:

#include<stdio.h>
int main()
{
    int a;
    char c;
    float f;
   printf("Enter a integer value ,character, float value:\n");
   scanf("%d%c%f",&a,&c,&f);
   printf("Integer value:%d\nCharacter:%c\nFloat value:%f",a,c,f);
   return 0;
}

Output:
   
Enter a integer value, character, float value: 
10
s
9.13
Integer value:10
Character:s
Float value:9.13

Note: printf() and scanf() are built-in functions present in stdio.h header file.

Points to remember:
  • %d,%c,%f are format specifiers in C, it helps the compiler identify the data type of variable we are going take as input or displaying.
  • '&' is the address operator in C. It helps the compiler change the actual value of this variable stored at this address in the memory.
  • '\n' is used for new line.
  • '\t' is used for tab space.


Comments