C a Label Can Only Be Part of a Statement

The reason is an error acquired by my announcement of variables subsequently the example
Analysis of this problem:
Due to switch a few case statement in the aforementioned scope (because a example statement is label, but they belong to a switch across constant-like block), so if in some case the post-obit statement variables, the scope of the object is between two curly braces, that is, the entire switch statement, other instance statement can also see that such things can pb to errors. We tin do this by calculation curly braces to the statements that follow the case. The reason for the braces is to specify the scope of the variables nosotros are declaring, just in this case. In fact, to write the switch-case statement more formally, nosotros should add curly braces subsequently the case argument.
Source code is as follows:

              #include <stdio.h>  int main(int argc, char *argv[]) {     int zt_num1 = i, zt_num2 = 2;      if (argc < 2) {         printf("delight input once more\n");         return -1;     }      if (!argv[one]) {         printf("please input once again\n");         render -1;     }      switch(*argv[ane])     {     case '+':         zt_num1 = zt_num1 + zt_num2;         break;     instance '$':         zt_num1 = zt_num1 - zt_num2;         break;     case '#':         int num = 3;         zt_num1 = zt_num1 + zt_num2 + num;         break;     default:         printf("please input again\north");         break;     }     printf("%d\n", zt_num1);      return 0; }                          

The compilation results are as follows:

The modified code is as follows:

              #include <stdio.h>  int main(int argc, char *argv[]) {     int zt_num1 = one, zt_num2 = 2;      if (argc < 2) {         printf("delight input again\north");         return -1;     }      if (!argv[1]) {         printf("delight input again\n");         render -ane;     }      switch(*argv[1])     {     case '+':         zt_num1 = zt_num1 + zt_num2;         break;     case '$':         zt_num1 = zt_num1 - zt_num2;         break;     case '#':     {         int num = 3;         zt_num1 = zt_num1 + zt_num2 + num;         interruption;     }     default:         printf("please input again\north");         break;     }     printf("%d\northward", zt_num1);      return 0; }                          

The compilation and operation results are:

Read More:

bledsoewasing1988.blogspot.com

Source: https://programmerah.com/error-a-label-can-only-be-part-of-a-statement-and-a-declaration-is-not-a-statement-how-to-fix-6416/

0 Response to "C a Label Can Only Be Part of a Statement"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel