DEV Community

Sujith V S
Sujith V S

Posted on • Edited on

Input and Output in C

In C programming printf() is used for outputting a data or to display a data. On the other hand, scanf() is used to take input values from the users.

Input and Output of integer value.

#include <stdio.h> int main() { int age; printf("Enter Input value: "); scanf("%d", &age); printf("Age = %d", age); return 0; } 
Enter fullscreen mode Exit fullscreen mode

Why we use & with scanf()

It is because, & helps to point towards the memory location of that variable.

Input and Output of double and char values

int main() { char alphabet; double number; printf("Enter a character: "); scanf("%c", &alphabet); printf("Enter a number: "); scanf("\n%lf", &number); printf("alphabet is %c", alphabet); printf("\nnumber is %.2lf", number); return 0; } 
Enter fullscreen mode Exit fullscreen mode

Inputting 2 values together

#include <stdio.h> int main() { char alphabet; double number; printf("Enter input values: "); scanf("%lf %c", &number, &alphabet); printf("alphabet is %c", alphabet); printf("\nnumber is %.2lf", number); return 0; } 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)