Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can anyone explain the output of this C program? [duplicate]

Tags:

People also ask

What is duplicate elements in C?

In this program, we need to print the duplicate elements present in the array. This can be done through two loops. The first loop will select an element and the second loop will iteration through the array by comparing the selected element with other elements.

Are duplicates allowed in array?

The array can be used as a HashMap. Problem in the below approach. This approach only works for arrays having at most 2 duplicate elements i.e It will not work if the array contains more than 2 duplicates of an element.

Can set have duplicate values C?

It works by creating a Set (which, by definition, cannot contain duplicates), initially containing all the elements in c .


Possible Duplicate:
Why can't variables be declared in a switch statement?
How can a variable be used when its definition is bypassed?

#include<stdio.h>
  int main()
  {
      int a=1;
      switch(a)
      {   int b=20;
          case 1: printf("b is %d\n",b);
                  break;
          default:printf("%d\n",b);
                  break;
      }
      return 0;
  }

ran on gcc 4.6.3, output not 20. What is going on here?