Write the difference between printf(), scanf(), putchar(), getchar(), char, string ?

by ManinderSinghPatiala
4 minutes read

Here’s a breakdown of the key differences between the functions you mentioned:

1. printf():

  • Purpose: Used to format and print output to the console.
  • Syntax: printf("format string", arguments);
  • Examples:
    • printf("Hello, world!\n");
    • printf("Age: %d, Name: %s\n", age, name);

2. scanf():

  • Purpose: Used to read formatted input from the console.
  • Syntax: scanf("format string", &variables);
  • Examples:
    • scanf("%d", &age);
    • scanf("%s", name);

3. getchar():

  • Purpose: Reads a single character from the console.
  • Syntax: char ch = getchar();
  • Example: ch = getchar();

4. putchar():

  • Purpose: Prints a single character to the console.
  • Syntax: putchar(character);
  • Example: putchar('A');

5. char:

  • Purpose: A data type used to store a single character.
  • Example: char letter = 'A';

6. string:

  • Purpose: Not a built-in type in C, but often refers to a character array (null-terminated sequence of characters).
  • Example: char name[] = "Bard";

Key Differences Summary:

Function Purpose Input/Output
printf() Formatted output to console Output
scanf() Formatted input from console Input
getchar() Read a single character Input
putchar() Print a single character Output
char Data type for single character N/A
string Character array (informal term) N/A

Related Posts

Leave a Reply

MSTIPS LOGO

From schoolrooms to YouTube, Maninder Singh’s passion for tech education knows no bounds. MsTips.in empowers learners of all ages with tips, tricks, and resources in multiple languages. Dive into IT tutorials, explore cyber safety, and embrace the fun side of tech—all in one vibrant space!

Copyright © 2023  All Right Reserved – Designed and Developed by Maninder Singh

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00