0% found this document useful (0 votes)
14 views10 pages

Programming Concepts

Uploaded by

vanhezjavier
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
14 views10 pages

Programming Concepts

Uploaded by

vanhezjavier
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 10

PROGRAMMING

. C Language:

 Type: Procedural Programming Language


 Level: Low-level (close to hardware)
 Compiled/Interpreted: Compiled
 Memory Management: Manual (you need to manage memory using malloc() and free())
 Use Case: System-level programming, embedded systems, operating systems, hardware
drivers.
 Syntax: Relatively simple but can be harder due to manual memory management.
 Speed: Very fast, as it is close to machine language.
 Portability: Code written in C may require modification for different platforms.
 Key Characteristics:
o Direct memory access (using pointers).
o No object-oriented features.

C++ Language:

 Type: Object-Oriented Programming (OOP) Language, also supports procedural


programming.
 Level: Mid-level (adds high-level abstractions on top of C)
 Compiled/Interpreted: Compiled
 Memory Management: Manual (with support for RAII, which simplifies memory
handling)
 Use Case: Game development, high-performance applications, system/software
development.
 Syntax: Complex, especially with OOP features (classes, inheritance, etc.)
 Speed: High performance, often used in resource-constrained environments.
 Portability: Like C, but C++ programs can be more portable across platforms.
 Key Characteristics:
o Supports both procedural and object-oriented programming.
o Extensive use of templates and overloading for flexibility.

Java Language:

 Type: Object-Oriented Programming Language


 Level: High-level
 Compiled/Interpreted: Compiled to bytecode, then interpreted by the Java Virtual
Machine (JVM)
 Memory Management: Automatic (garbage collection)
 Use Case: Web applications, enterprise-level applications, Android app development.
 Syntax: More verbose than Python, but consistent and widely used.
 Speed: Slower than C/C++ but faster than Python due to JVM optimizations.
 Portability: "Write Once, Run Anywhere" (WORA) - runs on any system with a JVM.
 Key Characteristics:
o Strongly typed (variables must be declared with a specific type).
o Platform independence through JVM.
o Large ecosystem, especially for enterprise applications.

Python Language:

 Type: Interpreted, High-Level Programming Language


 Level: High-level
 Compiled/Interpreted: Interpreted
 Memory Management: Automatic (with garbage collection)
 Use Case: Web development, data science, artificial intelligence, automation, scripting.
 Syntax: Simple and easy to read (often considered beginner-friendly).
 Speed: Slower compared to C/C++ because of its high-level nature and interpreted
execution.
 Portability: Highly portable, works across different platforms without modification.
 Key Characteristics:
o Dynamic typing (variables do not need explicit declaration).
o Large ecosystem of libraries for various domains (AI, web development, etc.).
o Object-oriented, but also supports functional and procedural programming.

Basic Concepts of Programming


Programming is the process of designing and building an executable computer program to
accomplish a specific computing result. It involves writing code in a programming language that
a machine can understand. Here are a few fundamental concepts:

 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.

Operators and Expressions


 Operators are symbols that tell the computer to perform specific operations on variables
and values. Some common types include:
o Arithmetic Operators: +, -, *, /, % (addition, subtraction, multiplication,
division, modulus)
o Relational Operators: ==, !=, <, >, <=, >= (comparison between two values)
o Logical Operators: && (AND), || (OR), ! (NOT)
o Assignment Operators: =, +=, -=, *=, /=
o Bitwise Operators: &, |, ^, ~, <<, >>

 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.

Loops: Loops allow a block of code to be executed repeatedly.

 For Loop: Used when the number of iterations is known.


 While Loop: Repeats as long as a given condition is true

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.

 int num = 10;


Declares an integer variable num and assigns it the value 10.
 if (num > 5) {
} else {
}

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."

 for (int i = 0; i < 5; i++) {


}

A for loop that runs 5 times, printing the value of i from 0 to 4. The loop increments i in each
iteration.

 printf("i = %d\n", i);


Prints the value of i in each iteration. %d is a placeholder for an integer.

C++ Language
 #include <iostream>
Includes the input/output stream library, which provides the cout and cin objects for output and
input.

 using namespace std;


This allows you to use standard library functions without prefixing them with std::.

 int main() {}
The main entry point for the program.

 int num = 10;


Declares and assigns an integer variable num with the value 10.

 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."

 cout << "message" << endl;


Used to print output to the console. endl is used to move the cursor to the next line.

 for (int i = 0; i < 5; i++) {


}

A for loop that prints the value of i from 0 to 4 using cout.

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.

 public static void main(String[] args) {}


The main method where execution begins. It's static because it can be run without creating an
object, and void means it doesn't return anything.

 int num = 10;


Declares and assigns an integer variable num with the value 10.

 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.

You might also like