Computer Programming – Basic Syntax

Before diving into advanced programming concepts, it’s important to understand how basic syntax works in different Computer Programming languages. Syntax refers to the rules and structure that determine how code must be written so the computer can understand and execute it correctly.

In this chapter, we will start with simple “Hello, World!” examples in C, Java, and Python to help you understand the foundations of program structure, functions, statements, comments, whitespaces, and syntax errors.


Writing Your First Program

Let’s begin with a simple task—displaying the message “Hello, World!” on the screen. This is usually the first program beginners write, regardless of the programming language.

Below are examples of the same program written in C, Java, and Python.


Hello World Program in C

#include <stdio.h>

int main() {
   /* printf() function to write Hello, World! */
   printf("Hello, World!");
}

Output:

Hello, World!

Try changing the text inside printf() and observe the output. Whatever you place within double quotes gets printed on the screen.


Understanding Program Structure in C

Program Entry Point

Every C program starts with the function main(). The opening { marks the beginning of the program body, and the closing } marks its end. Everything between these braces is part of the program.

Functions

Functions are blocks of code created for specific tasks.
In the above program:

  • main() is the entry point
  • printf() prints text to the screen

C has many built-in functions, and you can also create your own.

Comments

Comments help explain code. They are ignored by the compiler.

In C:

/* This is a comment */

You can write comments in any language you prefer since they do not affect program execution.


Whitespaces in Programming

Whitespace characters include:

  • New Line\n
  • Tab\t
  • Space

These make your code readable but are usually ignored by the compiler.

Example with extra spaces (still works fine):

#include <stdio.h>

int main() {

   /* printf() function */
   printf(    "Hello, World!"      );

}

Semicolons in C

Every statement in C must end with a semicolon (;).

Example printing two lines:

printf("Hello, World!\n");
printf("Hello, World!");

Without \n, both messages appear on the same line.


Explaining the C Program Execution Process

  1. Write the program (e.g., in test.c)
  2. Compile it: gcc test.c -o demo
  3. If syntax errors exist, fix them
  4. Execute it: ./demo

Output:

Hello, World!

Syntax Errors in Programming

A syntax error occurs when you break the rules of the programming language.

Example (missing semicolon):

#include <stdio.h>

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

Compiler output:

error: expected ';' before '}' token

A single missing symbol is enough to break the entire program.


Hello World Program in Java

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

Output:

Hello, World!

Java programs must be compiled before execution, similar to C.


Hello World Program in Python

# print function to write Hello, World!
print("Hello, World!")

Output:

Hello, World!

Python is an interpreted language, which means:

  • No compilation is required
  • New lines, not semicolons, mark statement endings

Key Differences Between C, Java, and Python

FeatureCJavaPython
Needs compilationYesYesNo
Semicolon requiredYesYesNo
Entry pointmain()main() methodNo fixed structure
Print functionprintf()System.out.println()print()
basic programming syntax, hello world program, syntax error examples, C program structure, Java hello world, Python print statement, programming basics for beginners

Frequently Asked Questions (FAQ)

Why do most tutorials start with “Hello, World!”?

It is a simple way to demonstrate the minimum structure required to run a program in any language.

Why does C require semicolons?

Semicolons tell the compiler where a statement ends, helping it parse the code correctly.

Why doesn’t Python need semicolons?

Python uses new lines and indentation to determine code structure.

What causes syntax errors?

Missing characters, incorrect symbols, or violating language rules cause syntax errors.

Why does C use main() as the entry point?

It tells the compiler where the program begins execution.

Do all programming languages require compilation?

No. Languages like C and Java require compilation, while Python and PHP use interpreters.

Related Article
Computer Programming Tutorial for Beginners – Learn Coding Step by Step (C, Python, Java)

Computer Programming Tutorial for Beginners – Learn Coding Step by Step Computer programming is the process of writing a series Read more

Computer Programming Overview

Computer Programming Overview Computer programming begins with understanding what a computer program is and how it operates. A computer program Read more

Computer Programming Basics

Computer Programming – Basics Understanding computer programming begins with learning the foundational building blocks that every programming language is built Read more

Computer Programming Environment

Computer Programming – Environment Before writing your first computer program, you must prepare the correct programming environment. Although the environment Read more

Computer Programming – Data Types

Data types are one of the most important concepts in programming. A data type defines the kind of data a Read more

Computer Programming Variables

In any programming language, a variable is one of the most fundamental concepts. A variable acts as a named storage Read more

Computer Programming – Keywords

In earlier chapters, you learned two essential programming concepts: variables and data types. You also saw how different data types Read more

Computer Programming – Basic Operators

Basic Operators In every programming language, operators are the symbols used to perform operations on values and variables. Think of Read more

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Prove your humanity: 7   +   2   =