


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This document provides a clear and well-structured explanation of Variables in C Programming, focusing on Local and Global Variables. It includes definitions, syntax, characteristics, code examples, a comparison table, and important differences between the two types of variables. This material is suitable for students studying Computer Science, Engineering, or anyone learning C Language basics in their first or second semester. Topics covered: What is a Variable? Syntax of Variable Declaration Types of Variables in C Detailed explanation of Local and Global Variables Quick quiz for self-evaluation
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!
A variable in C is a named location in memory where data is stored. It acts as a container to hold values that may change during the execution of a program.
Key Points:
Each variable must have a unique name (called an identifier).
Variables must be declared before use.
They store data of specific types (like int, float, char, etc.).
data_type variable_name;
Example:
int age; float price; char grade;
Variables in C can be categorized based on their scope (where they are accessible) and lifetime (how long they exist in memory). The two most common types are:
● Local Variables
● Global Variables
Definition:
Local variables are declared inside a function or a block (like inside main() or an if block). They are accessible only within that function or block.
Key Characteristics:
Scope : Limited to the function or block.
Lifetime : Exists only while the function is executing.
Automatically destroyed after the function ends.
Must be initialized before use.
Example:
#include <stdio.h>
void display() { int x = 10; // Local variable printf("Value of x: %d\n", x); }
int main() { display(); // printf("%d", x); // Error: x is not accessible here return 0; }
Definition: