What are Variables in C Language?
What are Variables in C Language?
Variables in the C programming language are named memory locations that are used to store and manipulate data. A variable is essentially a symbolic name given to a specific location in the computer's memory, where values can be stored and accessed during the execution of a program.
In C, variables must be declared before they can be used. The declaration specifies the name of the variable and its data type, which determines the kind of values it can hold. Common data types in C include integers, floating-point numbers, characters, and arrays.
Here is an example of declaring and using variables in C:
#include <stdio.h>
int main() {
int age; // Declaration of an integer variable named "age"
float height; // Declaration of a floating-point variable named "height"
char grade; // Declaration of a character variable named "grade"
age = 25; // Assigning a value to the "age" variable
height = 175.5; // Assigning a value to the "height" variable
grade = 'A'; // Assigning a value to the "grade" variable
printf("Age: %d\n", age); // Printing the value of "age"
printf("Height: %.2f\n", height); // Printing the value of "height"
printf("Grade: %c\n", grade); // Printing the value of "grade"
return 0;
}
In the above example, we declare three variables: "age" of type integer, "height" of type float, and "grade" of type char. We then assign values to these variables using the assignment operator (=). Finally, we print the values of the variables using the `printf` function.
Variables in C can be modified by assigning new values to them, allowing data to be updated and manipulated throughout the program. They provide flexibility and allow programmers to work with different types of data efficiently.
हिंदी:
Post a Comment