𝗗𝗲𝗲𝗽 𝗗𝗶𝘃𝗲 𝗶𝗻𝘁𝗼 𝘁𝗵𝗲 𝘀𝘁𝗮𝘁𝗶𝗰 𝗦𝘁𝗼𝗿𝗮𝗴𝗲 𝗖𝗹𝗮𝘀𝘀 𝗶𝗻 𝗖 💡 The 𝙨𝙩𝙖𝙩𝙞𝙘 storage class is one of the most powerful and unique tools because its behavior completely changes depending on where you define it. While other storage classes like 𝘢𝘶𝘵𝘰 or 𝘳𝘦𝘨𝘪𝘴𝘵𝘦𝘳 are straightforward, 𝙨𝙩𝙖𝙩𝙞𝙘 has a "split personality" that manages both memory lifetime and linking visibility. Here is the simple breakdown from this infographic: 🔒 𝟭. 𝘀𝘁𝗮𝘁𝗶𝗰 𝗶𝗻𝘀𝗶𝗱𝗲 𝗮 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻 (𝗜𝗻𝘁𝗲𝗿𝗻𝗮𝗹 𝗠𝗲𝗺𝗼𝗿𝘆) 𝗦𝘁𝗼𝗿𝗮𝗴𝗲 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆: Internal static storage. 𝗟𝗶𝗳𝗲𝘁𝗶𝗺𝗲: Program-level. It is not destroyed when the function exits. 𝗦𝗰𝗼𝗽𝗲: Function/Block-level. It can only be seen and modified by that specific function. It's a private variable with a perfect memory! 🌐 𝟮. 𝘀𝘁𝗮𝘁𝗶𝗰 𝗼𝘂𝘁𝘀𝗶𝗱𝗲 𝗮 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻 (𝗚𝗹𝗼𝗯𝗮𝗹 𝗙𝗶𝗹𝗲 𝗦𝗰𝗼𝗽𝗲) 𝗦𝘁𝗼𝗿𝗮𝗴𝗲 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆: Global static storage. 𝗟𝗶𝗳𝗲𝘁𝗶𝗺𝗲: Program-level. Exists for the entire duration of the program. 𝗦𝗰𝗼𝗽𝗲: File-level. It is shared and can be changed by any function within that single .c file, but it is strictly hidden from functions in any other .c file in your project. It's like a family secret—shared with everyone inside the family (file) but hidden from outsiders (other files)! #CProgramming #EmbeddedSystems #Coding #SoftwareEngineering #StorageClass #LinkedInLearning
Understanding Static Storage in C: Function vs Global Variables
More Relevant Posts
-
Day 52 on LeetCode — Minimum Recolors to Get K Consecutive Black Blocks 🧩✅ Today’s problem was another clean application of the Sliding Window technique with optimization. 🔹 Approach Used in My Solution The goal was to find the minimum number of recolors (W → B) needed to get k consecutive black blocks. Key idea in the solution: • Treat it as finding a window of size k with minimum 'W' (white blocks) • Count the number of 'W' in the first window of size k • Slide the window across the string: – Remove the left character (if it was 'W') – Add the new right character (if it is 'W') • Keep track of the minimum changes required This avoids recomputation and ensures an efficient linear solution. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Strengthened understanding of fixed-size sliding window problems • Learned how to convert problems into min/max count in a window • Reinforced optimizing from brute force to O(n) solutions #LeetCode #DSA #Algorithms #DataStructures #SlidingWindow #Strings #TwoPointers #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
👉We Engineers don’t worry about “Log kya kahenge” 🤷♂️ We worry about “logs() kya kahenge” 💻📊 Because opinions don’t debug production… logs() do. While others chase validation, engineers chase: stack traces error messages and that one missing semicolon at 2 AM 🌙 No matter how perfect your code looks if the logs() are silent… something’s wrong. But when your logs() are clear? You’re unstoppable 🚀 Build. Break. Log. Fix. Repeat. 🔁 What’s the most confusing bug you’ve solved using logs()? 👇 #SoftwareEngineering #DeveloperLife #Debugging #TechCommunity #Programming #BuildInPublic
To view or add a comment, sign in
-
-
🛑 Can you spot the memory bug? Most of us think we understood object layout, but this snippet hides a "silent killer." 💣 class Test { public: int a; int b; virtual void fun() {} // The "Hidden" Player Test(int t1, int t2) : a(t1), b(t2) {} }; int main() { Test obj(5, 10); int* pInt = (int*)&obj; *(pInt + 0) = 100; // Guess what happens here? *(pInt + 1) = 200; cout << obj.a; } 🧠 The Reality Check We might expect obj.a to print 100. But it won’t, because of this virtual function, compiler inserts a vPtr at the very start of the object. 💡 The Lesson Virtual keyword doesn't just enable polymorphism, it physically reshapes data in memory. Manual pointer arithmetic on classes is a one-way ticket to undefined behaviour. Have you ever been faced such hidden compiler-injected members? Let’s talk in the comments! 👇 #Cpp #Programming #Coding #SoftwareEngineering
To view or add a comment, sign in
-
-
Declaration of Pointers in C can be a little tricky.. Many developers use pointers every day in C… but still get confused between these two declarations. const int *ptr; int *const ptr; 1️⃣ Pointer to Constant int x = 10; int y = 20; const int *ptr = &x; ptr = &y; // ✅ Allowed *ptr = 30; // ❌ Not Allowed Here the value being pointed to is constant. That means: ✔ Pointer can change address ❌ Value cannot be modified through pointer ptr ----> value (read-only) 2️⃣ Constant Pointer int x = 10; int y = 20; int *const ptr = &x; ptr = &y; // ❌ Not Allowed *ptr = 30; // ✅ Allowed Here the pointer itself is constant. That means: ❌ Pointer cannot change address ✔ Value can be modified Think of it as: constant ptr ----> value (modifiable) 🔑 The Golden Rule (Very Easy Trick) Look right of the pointer first. const int *ptr const applies to int → value constant int *const ptr const applies to ptr → pointer constant 👇👇Lets discuss below tricky questions in comments to get more clarity!! 👉Code snippet 1 int x = 10; const int *ptr = &x; x = 20; printf("%d", *ptr); What will be printed? A) Compilation error B) 10 C) 20 D) Undefined behavior 👉Code snippet 2 What will happen in the following code? int x = 10; const int *ptr = &x; int *p2 = (int *)ptr; *p2 = 50; printf("%d", x); What is the correct answer? A) Compilation error B) 10 C) 50 D) Undefined behavior #EmbeddedSystems #EmbeddedC #CProgramming #Pointers #EmbeddedEngineer #FirmwareDevelopment #LowLevelProgramming #EmbeddedInterview #BitManipulation #ProgrammingTips
To view or add a comment, sign in
-
🚀 Day 527 of #750DaysOfCode 🚀 Today I solved LeetCode 3130 – Find All Possible Stable Binary Arrays II (Hard). 🔹 Problem Summary We are given three integers: zero, one, and limit. A binary array is considered stable if: • It contains exactly zero number of 0s • It contains exactly one number of 1s • No subarray longer than limit contains identical elements (meaning we cannot have more than limit consecutive 0s or 1s) The task is to calculate the total number of such stable arrays, with the result taken modulo (10^9 + 7). 🔹 Approach This problem builds on the previous version but with larger constraints, requiring an optimized solution. I used: • Dynamic Programming to track combinations of zeros and ones • State tracking based on the last placed digit (0 or 1) • Sliding window / prefix optimization to efficiently enforce the limit constraint 🔹 Key Concepts Practiced • Dynamic Programming • State transition optimization • Prefix sums / sliding window technique • Modular arithmetic • Handling large constraints efficiently Problems like this are a great reminder that optimization techniques are just as important as the core algorithm. Consistency continues… one day at a time. 💻🔥 #leetcode #dsa #dynamicprogramming #codingchallenge #softwareengineering #programming #developers #learninginpublic #techjourney #750daysofcode
To view or add a comment, sign in
-
-
🚀 Day 180 of #200DaysOfCoding Today I solved “Special Positions in a Binary Matrix” on LeetCode. 🧠 Problem Idea: We are given a binary matrix and need to count positions where the value is 1 and all other elements in the same row and column are 0. Such positions are called special positions. 💡 Approach: Instead of checking the entire row and column every time, we can optimize by: • Counting the number of 1s in each row • Counting the number of 1s in each column • A cell (i, j) is special if: mat[i][j] == 1 rowCount[i] == 1 colCount[j] == 1 This reduces unnecessary checks and keeps the solution efficient. ⏱ Time Complexity: O(m × n) 📦 Space Complexity: O(m + n) 💻 Language Used: C++ Consistency is the real key. Every day of problem solving improves logical thinking and problem-solving ability. Just 20 more days to complete the #200DaysOfCoding challenge! 💪 #leetcode #codingchallenge #programming #cpp #datastructures #algorithms #softwaredevelopment
To view or add a comment, sign in
-
-
“My code passed 𝟏𝟎𝟎+ test cases… so I thought I was done.” 😌 Then test case 118 happened. 💀 I was solving the 𝐋𝐨𝐧𝐠𝐞𝐬𝐭 𝐈𝐧𝐜𝐫𝐞𝐚𝐬𝐢𝐧𝐠 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 (LIS) problem using Dynamic Programming (𝐑𝐞𝐜𝐮𝐫𝐬𝐢𝐨𝐧 + 𝐌𝐞𝐦𝐨𝐢𝐳𝐚𝐭𝐢𝐨𝐧). Everything looked perfect. Clean code. Correct logic. And most importantly — it was passing. Until it didn’t. Large test cases started crashing with runtime errors. That’s when it hit me… 👉 The problem wasn’t my code. 👉 The problem was my thinking. I was using an O(n²) approach for constraints up to 10⁵. No matter how “correct” it is… it’s not scalable. So I switched to the O(n log n) solution using 𝐁𝐢𝐧𝐚𝐫𝐲 𝐒𝐞𝐚𝐫𝐜𝐡. Same problem. Same goal. Completely different performance. 💡 That moment changed how I look at problems: Correct ≠ Efficient Passing ≠ Scalable 𝘿𝙤 𝙮𝙤𝙪 𝙥𝙧𝙞𝙤𝙧𝙞𝙩𝙞𝙯𝙚 𝙘𝙤𝙧𝙧𝙚𝙘𝙩𝙣𝙚𝙨𝙨 𝙛𝙞𝙧𝙨𝙩 𝙤𝙧 𝙨𝙘𝙖𝙡𝙖𝙗𝙞𝙡𝙞𝙩𝙮 ? #DataStructures #Algorithms #DynamicProgramming #CodingJourney #SoftwareEngineering #ProblemSolving #TechLearning #LearnInPublic #Developers #Coding
To view or add a comment, sign in
-
One design principle you’ll hear often in software engineering Composition over inheritance But what does that actually mean? Inheritance creates relationships based on “is-a”. Composition creates relationships based on “has-a”. The problem with inheritance is that as systems grow, class hierarchies tend to grow with them. You start with a simple structure, but over time more and more variations appear and the hierarchy becomes harder to maintain. Composition takes a different approach. Instead of building large inheritance trees, objects are built by combining smaller pieces of behavior. This usually leads to designs that are more flexible and easier to evolve. Look at the example below. It’s a small idea, but understanding it can significantly improve how you design systems. #SoftwareEngineering #Programming #ObjectOrientedProgramming #OOP #DesignPatterns #SoftwareDesign #CleanCode #CodingBestPractices
To view or add a comment, sign in
-
-
"𝐈𝐭 𝐰𝐨𝐫𝐤𝐬 𝐨𝐧 𝐦𝐲 𝐦𝐚𝐜𝐡𝐢𝐧𝐞" - how many times have I heard that while being trapped in a "dependency nightmare"? One error leads to another, and three hours later, I’m still installing libraries instead of running code. I built #CrashFixer to end the "it works on my machine" lie. One command, zero friction. By containerizing the entire debugging flow with 𝐃𝐨𝐜𝐤𝐞𝐫, I’ve isolated the mess into three clean stages: 🏗️ 𝐓𝐡𝐞 𝐁𝐮𝐢𝐥𝐝𝐞𝐫: Compiles C/C++ and generates the crash data. 🧠 𝐓𝐡𝐞 𝐋𝐥𝐚𝐦𝐚-𝐒𝐞𝐫𝐯𝐞𝐫: Runs a local LLM for private, local-first crash resolution. 🛠️ 𝐓𝐡𝐞 𝐀𝐧𝐚𝐥𝐲𝐳𝐞𝐫: Runs GDB, parses the crash data, and queries the LLM to output a fix. No global installs. No "never-ending chain of errors." Just a clean path from Segfault to Solution. 🚀 Stop debugging your environment and start fixing your code. #SoftwareEngineering #Docker #LLM #Cpp #Programming #OpenSource #Debugging #CrashFixer
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development