What is the format specifier used to print a String or Character array in C Printf or Scanf function?
Select one:
O a. %s
O b. %w
O c.%c
O d. %C
Answers
%s is the format specifier used to print a String or Character array in C Printf or Scanf function.
a. %s
Extra Information
There are various types of format specifier in C which is used to either take the input from the user or to show output to the user. Some common format specifiers are
1. %d
This format specifier is used for integer values or int values
2. %c
This format specifier is used for characters.
3. %s
This format specifier is used for string
4. %f
This format specifier is used for float values or decimal values.
Example
#include <stdio.h>
int main()
{
int integerValue;
float floatValue;
char character;
char string[20];
scanf("%d %f %c %s", &integerValue, &floatValue, &character, string);
printf("%d \n %f \n %c \n %s", integerValue, floatValue, character, string);
}
Input
5
5.22
A
HelloWorld
Output
5
5.220000
A
HelloWorld
\n is used to print output in a new line.
Option a is the correct answer. %s is used as the format specifier which prints a string in C printf or scanf function.
- In C, %s allows us to print by commanding printf() to print any corresponding argument in the form of a string.
- The argument used is "char*" for %s to print.
- %s does the same command for scanf also. There is a slight difference here, scanf() reads the sequence of characters until it is manually stopped by a space.
- Printf() in C programming language is used to print any character, string, integer, octal onto the output screen.
- In the "C "programming language, scanf() is used to take input from the user. It reads the input already present in the user.