Menu
Static variables in C++
Course Lessons
Free DSA Resources: Courses, YouTube Channels & 2026 Roadmap
A Career in Digital Marketing - A Complete Guide for Beginners
Structure of DBMS Explained: Components, Diagram & Architecture
Advanced Algorithms and Problem Solving Techniques
Data Structures: Foundation of Effective Programming
Importance of Banks: Role of Banking System in Economy, Business & Development
What Is Marketing? Definition, Types and Importance
STP Marketing Framework: Segmentation, Targeting and Positioning
What Is Branding? Meaning, Elements and Importance
What Is Digital Marketing and Why It Matters in India
Product Life Cycle: The 4 Stages Explained
Indian Brand Success Stories & Lessons
Content Marketing Strategy: A Step-by-Step Framework
Evolution of Marketing: Eras and Orientations
SEO vs SEM: Differences, Pros and Cons
GE-McKinsey Matrix: The Nine-Box Portfolio Model
Marketing Frameworks Cheat Sheet: Quick Reference
Email Marketing Best Practices That Drive Results
Influencer Marketing Strategy: A Complete Guide
The 9 Digital Marketing Channels Explained
Core Branding Concepts: Identity, Image and Equity
Marketing Mix Explained: The 4Ps and 7Ps
Sales vs Marketing: Key Differences Explained
Goods vs Services Marketing: What's the Difference?
AIDA Model: The 4 Stages of the Customer Journey
Brand Architecture Models: Branded House vs House of Brands
The Digital Marketing Funnel: Awareness to Conversion
B2B vs B2C Marketing: Differences, Examples and Strategy
BCG Matrix Explained: Stars, Cash Cows, Dogs & Question Marks
Case Study Frameworks for Analytics Interviews
Brand Extension vs Line Extension: Strategy, Fit and Risks
Digital Marketing Terms: CPC, CTR, ROAS and More
Kapferer's Brand Identity Prism: The 6 Facets
Ansoff Matrix: The 4 Growth Strategies with Examples
Customer Psychology in Marketing: Needs and Buyer Behaviour
Marketing Terms & Jargon: A Beginner Glossary
Porter's Five Forces: Industry Analysis Framework
Digital Marketing Jobs and Career Roles in India
Brand Positioning Bullseye Framework
PESTLE Analysis: Meaning, Factors and India FMCG Examples
Essential Digital Marketing Tools & Platforms for India
Co-Branding and Brand Personality Explained
What Is Brand Architecture? Types and Examples
AI and GenAI in Analytics - The Modern Analyst's Toolkit
Analytics Metrics Deep-Dive: A/B Testing and Retention
Brand Extension vs Line Extension: Meaning & Examples
Brand Differentiation: Practical Levers to Make a Brand Stand Out
Digital Marketing Frameworks for Campaign Planning
SWOT Analysis: How to Build One with Examples
Brand Equity Measurement and Brand Valuation
Keller's Brand Equity Model (CBBE Pyramid) Explained
The Marketing Environment: Micro and Macro Factors
Introduction to Big Data
Introduction to Deep Learning: From Basics to Advanced Concepts
Step-by-Step Guide to Data Visualization with Power BI
How To Start Your Career In Data Science
Data Communication: Process, Components, Types & Models for Networks
Basics of Javascript
Why is it Important for Freshers to Work in a Team?
The Multifaceted Relationships Between Banker and Customer
What are Node.js and Basics of Node.js?
Does a Linkedin profile really matter before getting a Job?
10 Common Data Structures Every Programmer Must Know
6 Bootstrap Tools and Playground – One-stop shop for all Web Developmental Needs
Introduction to Management Interview Preparation
Why Learn English?
Grooming and Etiquette: Complete Guide for Professional and Corporate Success
Getting Started with Tableau: Installation and Introduction
Discover the Versatility of Microsoft Excel: Your Swiss Army Knife for Data
What is Marketing? Core Concepts and Evolution of Marketing Eras
Header in C++
Ultimate Guide to HR Interview Questions for Freshers
JSON vs XML: Differences
Why Social Media Marketing Is Important?
Why Data Visualization is Important for Becoming a Data Scientist
Most Common 10 Telephonic Interview Questions
Fundas of Pandas
What is the Scope of Digital Marketing in 2025
A quick guide to Asymptotic Analysis
Operating System: Functions
Data Science vs. Data Analytics - What's the Difference?
Types of Data in Statistics
What are Collections in Python?
What is Search Engine Optimization & How It Works
OOPs (Object Oriented Programming) in C++
Understand Serialization and Deserialization in Java
What is Full Stack Development?
Javascript vs Typescript: What is the Difference?
Introduction to Big Data Analytics: From Basics to Implementation
Fundamentals of Digital Marketing
Introduction To SQL: A Complete Guide
Introduction to Goal Setting and Risk Profiling
How To Start Competitive Programming - A Complete Guide
How to Apply for Jobs as Fresher & Get Selected in One Go
All about C Programming Language
Learn about Boolean in Python
Software Testing: What it is?
What is Email Marketing in Digital Marketing?
Encapsulation in Java: A Comprehensive Tutorial
We will understand static variables along with its applications and use cases in C++ using examples in this article.
What is a Static Variable?
A var becomes a static variable if the static keyword was used before its definition.
Syntax
static <type> <variable_name>; |
The place where a static keyword is specified determines the purpose for which it is used. If a variable is defined within a class, all class instances—that is, all objects—will have the same version of the variables, and we may access it outside of the class without requiring any objects by calling it by its class name. Its value is maintained between calls if it is declared inside of a function for the duration of the programme, but it cannot be accessed outside of the function or scope in which it is defined. Let's look at some C++ examples of both categories of static variables.
Code
#include <iostream> |
Output: Num of 1st Object: 2 Num of 2nd Object: 2 |
Even though we haven't increased the num of the second object, the result shows that the values of num for both objects are the same. The fact that num has the same value in both objects shows that a static variable is shared by both of them.
Static Variable inside a Function
Code
#include <iostream> |
Output: 1 2 |
Watch the result in this scenario. In the main method, the increase() function has been called twice, with the second call returning the first call's increased value. This demonstrates that a static variable inside a function is only defined once during the initial function call, and all subsequent calls to the same function utilize the same copy.
All of the objects in a class share a static variable with it. A static variable included within a function or scope stays in memory for the duration of the programme.
Static Variable Uses
When we wish to reuse a variable's altered value from one function call to the next, we should utilize a static variable. Or if we want the class variable to remain constant across all objects. In this course, we learnt what a static variable in C++ is, how important it is, and when to utilize one.
Social Media Marketing in India: Platform Selection Guide