Skip to main content

Instantiated a variable not initialized :


#include<stdio.h>
int main(int argc,char *argv[])
{
    int ch = 1;
    switch(ch){
     int v = 100;
     case 1:
            printf("Value of v is = %d\n",v);
            break;
     default:
            printf("Value of v is = %d\n",v);
            break;    
    
   }
    
    return 0;
}

In this code if we compile and run this code we will get garbage value or (0). Reason behind this
we have instantiated but not initialized this variable. We can check this thing through using gdb.
In beow image we can see after switch control directly jump on case 1: and print value of variable.

Comments