Programming Concepts
Programming Concepts
. C Language:
C++ Language:
Java Language:
Python Language:
Syntax: Every programming language has its own rules (syntax) for writing valid
instructions.
Variables: Containers for storing data values that can be used and modified in the
program.
Data Types: Types of data, such as integers, floats, strings, and booleans that variables
can hold.
Functions: Blocks of reusable code that perform a specific task. A function is called by
name whenever needed.
Algorithms: Step-by-step instructions for solving a problem or performing a task.
Debugging: The process of identifying and fixing errors in a program.
Expressions are combinations of values, variables, and operators that are evaluated to
produce a new value. For example, x + y * z is an expression where * is evaluated first,
and then the result is added to x.
Control Structures
Control structures are used to determine the flow of control in a program, allowing decisions to
be made, loops to be executed, and code blocks to be reused. The main types of control
structures are:
Conditional Statements (If-Else): These are used to perform different actions based on
different conditions.
Switch (or Match Statements): Allows you to choose between many options based on the value
of a variable.
EXAMPLE OF CODE
C
#include <stdio.h>
This includes the standard input/output library to enable the use of printf and other I/O
functions.
int main() {}
The main function where the program starts execution. The return type is int to return a status
code.
This is an if-else conditional structure. If num is greater than 5, it prints "Number is greater
than 5." Otherwise, it prints "Number is less than or equal to 5."
A for loop that runs 5 times, printing the value of i from 0 to 4. The loop increments i in each
iteration.
C++ Language
#include <iostream>
Includes the input/output stream library, which provides the cout and cin objects for output and
input.
int main() {}
The main entry point for the program.
if (num > 5) {
} else {
}
Same logic as in C. If num is greater than 5, it prints "Number is greater than 5." Otherwise, it
prints "Number is less than or equal to 5."
JAVA
public class Main {}
Defines a class called Main. In Java, every program must have at least one class, and Main is a
common choice for the name of the main class.
if (num > 5) {
} else {
}
Conditional structure. If num is greater than 5, it prints "Number is greater than 5." Otherwise, it
prints "Number is less than or equal to 5."
System.out.println("message");
This prints a message to the console. The System.out object handles the output.
for (int i = 0; i < 5; i++) {
}
A for loop that runs 5 times, printing the value of i from 0 to 4 using System.out.println.
Python
num = 10:
In Python, variables are dynamically typed, so no need to explicitly declare the type. num is
assigned the value 10.
if num > 5:
print("Number is greater than 5")
else:
print("Number is less than or equal to 5")
Conditional structure. If num is greater than 5, it prints "Numberis greater than 5." Otherwise, it
prints "Number is less than or equal to 5." Python uses indentation (4 spaces) to define blocks of
code.
print("message")
Used to print output to the console.
for i in range(5):
A for loop that iterates through the range 0 to 4. In Python, range(5) generates a sequence from
0 to 4.
print(f"i = {i}")
Prints the value of i using an f-string for formatted output.