One of the c-c++ syntax differences

I was dizzy by a C program today, and finally found out that I made a low-level mistake. It's all because of "object-oriented" for a few years, and I forgot the old capital of C.

Summarize the error as follows:

C language is different from C++. In C programming, all variables and constants that may be used in the function/procedure must be defined at the beginning of the function/procedure, because the division of memory addresses in C language is under DOS. Instead of the current segment page method, c first opens up the data segment in memory, and then opens the code segment.

For example:
#include <stdio.h>
void main()
{
  int a=10;
  printf("%d/n",a);
  int b=8;
  printf("%d/n",b);
}
in There will be errors under TC2.0. Put the declaration of b in front.
#include <stdio.h>
void main()
{
  int a=10;
  int b=8;
  printf("%d/n",a) ;
  printf("%d/n",b);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325849561&siteId=291194637