Reputation: 24500
#include <stdio.h>
#include <windows.h>
#include <iostream>
using namespace std;
int main(){
int n ;
cout << "insert n " <<endl ;
cin >> n ;
switch(n){
cout <<"inside switch " <<endl ;
case 2 :
cout << "this is 2 " <<endl ;
break ;
case 5 :
cout << "this is 5 " <<endl ;
break ;
default :
cout << "this is default - any number" <<endl ;
break ;
}
return 0 ;
}
Does switch structure print the cout before cases?
It does not , i checked it, is this a rule that inside switch only stuff inside cases will be printed?
Upvotes: 0
Views: 889
Reputation: 272667
A switch
is essentially just a computed goto
; the individual cases are essentially just labels.
In your example code, the switch will always jump past the first cout
statement.
Upvotes: 1