Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Variables:

In C, variables are used to store data that can be manipulated or accessed within a program. Here are some key points about variables in C:

1. Declaration: Before using a variable, you need to declare it. Variable declaration specifies the data type of the variable and optionally initializes its value.

int age; // Declaration of an integer variable float pi = 3.14; // Declaration and initialization of a floating-point variable char letter = 'A'; // Declaration and initialization of a character variable

2. Data Types: C supports various data types such as integers (int), floating-point numbers (float, double), characters (char), etc. Each data type has a specific size and range of values.

int num = 10; float salary = 1000.50; char grade = 'A';

3. Naming Convention: Variable names in C must begin with a letter (either uppercase or lowercase) or an underscore (_). They can be followed by letters, digits, or underscores. C is case-sensitive, so num, Num, and NUM are considered different variables.

int myNumber; float average_score; char firstInitial;

4. Scope: The scope of a variable determines where in the code it can be accessed. Variables declared within a function are typically local to that function, while variables declared outside of any function (at the global scope) are accessible throughout the entire program.

#include int globalVariable = 100; // Global variable int main() { int localVariable = 50; // Local variable printf("Global variable: %d\n", globalVariable); printf("Local variable: %d\n", localVariable); return 0; }

5. Constants: In C, you can declare constants using the const keyword. Once assigned a value, constants cannot be changed during program execution.

const int MAX_VALUE = 100;

6. Initialization: Variables can be initialized at the time of declaration or later in the program.

int x = 5; // Declaration and initialization int y; // Declaration y = 10; // Initialization
  1. Storage Classes: C supports different storage classes for variables, such as auto, static, extern, and register. These control aspects like lifetime, scope, and linkage of variables.

Variables play a crucial role in storing and manipulating data in C programs, and understanding how to declare and use them is fundamental to writing effective C code



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java