Introduction
Format specifiers tell the computer how to show or read different types of data like numbers or letters.
printf("format_specifier", value); scanf("format_specifier", &variable);
printf("%d", 10);
printf("%f", 3.14);
scanf("%c", &ch);printf("Hello %s", "World");
#include <stdio.h> int main() { int age = 25; float height = 5.9f; char initial = 'J'; printf("Age: %d\n", age); printf("Height: %.1f feet\n", height); printf("Initial: %c\n", initial); return 0; }
printf?%d specifier is used to print integer values in C.%f is for floats, %c for characters, and %s for strings.ch in C?%c.%s is for strings, %d for integers, and %f for floats, so they are incorrect for a character.int x = 10;
float y = 5.5;
printf("%d %f", x, y);
%d prints integer as is, %f prints float with 6 decimal places by default.x is 10 (int), printed by %d. y is 5.5 (float), printed by %f as 5.500000.char name[10];
scanf("%c", name);
%c reads a single character, but name is an array for a string.name, use %s which reads until whitespace.float pi = 3.14159; with only 2 decimal places. Which printf statement is correct?%.2f where 2 is the number of decimals.%2f sets minimum width, not decimals; %f.2 is invalid; %f prints 6 decimals by default.Pass the test and this pattern moves unknown