Welcome to our BMR AI CHATBOT.
A free expermental AI tool where you can interact with the webpage, ask question about the webpage and other related doubts.
In some cases reponses may take time to get. In case of error give us your report.
You responses are stored for experimental purpuses. And your personal info is not integrated with you in any way.
Note: AI can make mistakes and can give in appropiate responses. Your feedbak will help us improve.
Stay tuned for more AI products and tools
And Finally don't forget to give your feedback. click on the icon provided to give feedback.
Used to store and manipulate data.
Each variable can be decalred with a data type that decribes the values it can hold.
Syntax - Declaring a variable
data_type variable_name;
Syntax - Initializing a variable
data_type variable_name = value;
Here we declare a value in view of the data type.
#include <stdio.h>
int main() {
int age; // Declaration
age = 25; // Initialization
float height = 1.75; // Declaration and initialization
char grade = 'A'; // Declaration and initialization
age = 19; // Modifiying a variable
return 0;
}
We can modifiy the variables after we declared or intialize the value for the varibale.
While modifying the type of the value should be same.
To declare a variable name correctely here are some rules
Rule
Description
Example
Valid Characters
Letters (uppercase and lowercase), digits, underscore
myVar, count_1, Total
Length
Any length, but only the first 31 characters matter
averageScore, temperature2
Reserved Keywords
Cannot be the same as C keywords
int, if, while (invalid)
Case Sensitivity
C is case-sensitive
myVar and myvar are different
Meaningful and Descriptive
Names should convey the purpose of the variable (Not important but recommended)
totalStudents, averageTemperature
No Spaces
Variable names cannot contain spaces
student_age, total Score (Invalid)
#include <stdio.h>
int main() {
int age; // Declaration
// Valid variable names
int age;
float average_score;
char _grade;
double temperature2;
int counter123;
// Invalid variable names
int 2ndPlace; // Starts with a digit
char student-age; // Contains invalid character '-'
double average mark; // Contains space
float if; // Reserved keyword
return 0;
}
We can use operators while assigning a value for the variable.
We can use addition, subraction, multiplication and more.
#include <stdio.h>
int main() {
double PI = 3.14159;
int radius = 5;
int result = PI*radius;
printf("The value is: %f\n", result);
return 0;
}
Declaring a variable const make the variable values cannot be modified.
Syntax
const data_type CONSTANT_NAME = value;
#include <stdio.h>
int main() {
const double PI = 3.14159;
printf("The value of PI is: %f\n", PI);
return 0;
}
We can access varibales in two ways
#include <stdio.h>
int globalVar = 10; // Global variable
int main() {
int localVar = 5; // Local variable
printf("Global variable: %d\n", globalVar);
printf("Local variable: %d\n", localVar);
return 0;
}
The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compiler.