添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Because I am getting error like this:
main.c:6:3: error: initializer element is not constant
What I have tried:
#include < stdio.h > #include < stdlib.h > struct Node{ int a; int b; a=( struct Node*)malloc( sizeof ( struct Node)); int main() printf( " Hello world" ); return 0 ; It's not inside a function, which means it has to be an initializer - which is assigned only when the item is declared - which means it must be a constant value at compile time, which malloc cannot be.
Move the line inside the main function and it'll work:
#include < stdio.h > #include < stdlib.h > struct Node{ int a; int b; int main() a=( struct Node*)malloc( sizeof ( struct Node)); printf( " Hello world" ); return 0 ;
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •