-
Notifications
You must be signed in to change notification settings - Fork 0
C_Data_Types.c
ani9977 edited this page Sep 11, 2024
·
1 revision
Here's the code with comments and explanations:
#include <stdio.h> // Includes the standard input-output library for input-output operations
int main() { // Main function where program execution begins
int myInt = 10; // Declares an integer variable 'myInt' and assigns the value 10 to it
float myFloat = 3.14; // Declares a float variable 'myFloat' and assigns the value 3.14
char myChar = 'A'; // Declares a character variable 'myChar' and assigns the value 'A'
// Prints the values of myInt, myFloat, and myChar using format specifiers
// %d for integers, %.2f for floats with two decimal precision, and %c for characters
printf("Integer: %d, Float: %.2f, Char: %c\n", myInt, myFloat, myChar);
return 0; // Returns 0, indicating the program executed successfully
}-
int myInt = 10;: Declares an integer variablemyIntand initializes it with the value 10. -
float myFloat = 3.14;: Declares a floating-point variablemyFloatand assigns it the value 3.14. -
char myChar = 'A';: Declares a character variablemyCharand assigns it the character 'A'. -
printf("Integer: %d, Float: %.2f, Char: %c\n", myInt, myFloat, myChar);: Thisprintffunction prints the values of the three variables.-
%dis the format specifier for integers. -
%.2fprints the float with 2 decimal places. -
%cis used to print characters.
-
-
return 0;: This indicates the program completed successfully.
In this program, we demonstrate the use of different data types in C: int, float, and char, and how to format their output using the printf function.