What kind of error is there in C code snippet? -
i examining errors in different c programs , differentiating between them.
currently, confused type of error there in code.
#include <stdio.h> int main(void) { in/*hello*/z; double/*world*/y; printf("hello world"); return 0; }
when run program, compilation error :
prog.c: in function 'main': prog.c:4:5: error: unknown type name 'in' in/*this example*/z; ^ prog.c:5:30: warning: unused variable 'y' [-wunused-variable] double/*is error?*/y; ^ prog.c:4:29: warning: unused variable 'z' [-wunused-variable] in/*this example*/z; ^
i know warning not prevent compiling, there error
error: unknown type name 'in'
so, syntax or semantic error ?
there syntax error. first of have clarify thing: have understand what's difference between syntax , semantics. syntax "grammar rules" of programming language, when compiler not compile, you've done syntax errors. when semantics error have done code compiles successfully, but, when executed things not want to. c strong-typed language: means have declare variables before using them. have done couple of errors, don't worry, let's analyze them together. first error: used type of variable not possible: , compiler showed up. "in" type i'm assuming meant int, when code have ask yourself: "is variable useful now?" answer question is: "no", because want make output. correct implementation of simple procedure is:
http://groups.engin.umd.umich.edu/cis/course.des/cis400/c/hworld.html
hope helps.
bye.
gerald
Comments
Post a Comment