write varriable in file C
Certainly! Here's an example of defining variables in a C file:
#include <stdio.h>
int main() {
// Declare variables
int integerVar;
float floatVar;
char charVar;
// Assign values to variables
integerVar = 10;
floatVar = 3.14;
charVar = 'A';
// Display the values
printf("Integer Variable: %d\n", integerVar);
printf("Float Variable: %f\n", floatVar);
printf("Character Variable: %c\n", charVar);
return 0;
}
Explanation:
- #include <stdio.h>
: This line includes the standard input-output library header file, which provides functions like printf
and scanf
.
- int main() { }
: The main function where the program execution begins.
- int integerVar; float floatVar; char charVar;
: Variable declarations for an integer, a floating-point number, and a character.
- integerVar = 10; floatVar = 3.14; charVar = 'A';
: Assigning values to the declared variables.
- printf()
: Function to display output to the console.
- %d
, %f
, %c
: Format specifiers used in printf
to display integer, float, and character values respectively.
- return 0;
: Indicates successful execution of the program by returning 0 from the main()
function.