c - Attribution in first line on switch statement make a error in gcc -


why code doesn't work unless remove comment?

#include <stdio.h>  int main(){     int num = 5;     switch(num){         case 5:             //printf("");             int = 1;             printf("%d", num+another);             break;     } } 

gcc returns error:

prog.c: in function ‘main’: prog.c:7:13: error: label can part of statement , declaration not statement 

thanks.

the reason outlined here: why can't variables declared in switch statement?

as workaround, can this:

#include <stdio.h>  int main(){     int num = 5;     switch(num){         case 5:;             //printf("");             int = 1;             printf("%d", num+another);             break;     } } 

include semicolon after case workaround.fool compiler thinking statement follows , not declaration. taken here


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -