Class: 07 Introduction to Computer Programming --- Complete Course for BSSE and BSCS Students Specially

 



Syntax Error

If you do not follow the rules defined by the programing language, then at the time of compilation, you will get syntax errors and the program will not be compiled. From syntax point of view, even a single dot or comma or a single semicolon matters and you should take care of such small syntax as well. In the following example, we have skipped a semicolon, let's try to compile the program −

#include <stdio.h>

main() {
   printf("Hello, World!")
}

This program will produce the following result −

main.c: In function 'main':
main.c:7:1: error: expected ';' before '}' token
 }
 ^

So the bottom-line is that if you are not following proper syntax defined by the programming language in your program, then you will get syntax errors. Before attempting another compilation, you will need to fix them and then proceed.

Hello World Program in Java

Following is the equivalent program written in Java. This program will also produce the same result Hello, World!.

public class HelloWorld { 
   public static void main(String []args) {
      /* println() function to write Hello, World! */
      System.out.println("Hello, World!");     
   }
}

which produces the following result −

Hello, World!

Hello World Program in Python

Following is the equivalent program written in Python. This program will also produce the same result Hello, World!.

#  print function to write Hello, World! */
print "Hello, World!"

which produces the following result −

Hello, World!

Hope you noted that for C and Java examples, first we are compiling the programs and then executing the produced binaries, but in Python program, we are directly executing it. As we explained in the previous chapter, Python is an interpreted language and it does not need an intermediate step called compilation.

Python does not require a semicolon (;) to terminate a statement, rather a new line always means termination of the statement.


Research Resources: Internet -- I am not owner of any thing!

Post a Comment

أحدث أقدم