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:

  1. #include <iostream>: Includes the necessary header file for input and output operations.

  2. int main() {: The main function, where the program execution begins.

  3. // Declare variables: Comments indicating the declaration of variables.

  4. int number = 10;: Declares an integer variable named 'number' and initializes it with the value 10.

  5. float floatingNumber = 3.14;: Declares a floating-point variable named 'floatingNumber' and initializes it with the value 3.14.

  6. char character = 'A';: Declares a character variable named 'character' and initializes it with the character 'A'.

  7. // Print variables using printf: Comments indicating the start of printing variables using printf.

  8. printf("Integer: %d\n", number);: Prints the integer variable 'number' using the format specifier %d.

  9. printf("Float: %f\n", floatingNumber);: Prints the floating-point variable 'floatingNumber' using the format specifier %f.

  10. printf("Character: %c\n", character);: Prints the character variable 'character' using the format specifier %c.

  11. return 0;: Indicates successful execution of the program.

  12. }: Closes the main function and the program.