printf cpp
#include <iostream>
int main() {
// Declare variables
int number = 10;
float floatingNumber = 3.14;
char character = 'A';
// Print variables using printf
printf("Integer: %d\n", number);
printf("Float: %f\n", floatingNumber);
printf("Character: %c\n", character);
return 0;
}
Explanation:
#include <iostream>
: Includes the necessary header file for input and output operations.int main() {
: The main function, where the program execution begins.// Declare variables
: Comments indicating the declaration of variables.int number = 10;
: Declares an integer variable named 'number' and initializes it with the value 10.float floatingNumber = 3.14;
: Declares a floating-point variable named 'floatingNumber' and initializes it with the value 3.14.char character = 'A';
: Declares a character variable named 'character' and initializes it with the character 'A'.// Print variables using printf
: Comments indicating the start of printing variables using printf.printf("Integer: %d\n", number);
: Prints the integer variable 'number' using the format specifier%d
.printf("Float: %f\n", floatingNumber);
: Prints the floating-point variable 'floatingNumber' using the format specifier%f
.printf("Character: %c\n", character);
: Prints the character variable 'character' using the format specifier%c
.return 0;
: Indicates successful execution of the program.}
: Closes the main function and the program.