Programming is the art of instructing computers to perform tasks and solve problems. At its core, it’s about giving step-by-step directions that a computer can understand and execute. To become proficient in programming, it’s essential to grasp key concepts that form the building blocks of code. Here are 50 definitions of basic programming concepts:
Variables:
- Variable: A container that holds a value, like a box storing information. Example:
int age = 25;
- Value: A piece of data stored in a variable. Example:
5
,3.14
,"Hello"
- Data Type: Defines the type of value a variable can hold. Example:
int
,float
,string
- Declaration: Creating a variable with a specific name and data type. Example:
int score;
- Initialization: Giving a variable its first value. Example:
score = 100;
Data Types:
- Integer: A whole number data type. Example:
int num = 10;
- Floating-Point: A data type for numbers with decimal places. Example:
float price = 19.99;
- String: A sequence of characters, like text. Example:
string name = "Alice";
- Boolean: A data type representing true or false values. Example:
bool isTrue = true;
Basic Operations:
- Arithmetic Operators: Symbols used for basic math operations. Example:
int sum = 5 + 3;
- Concatenation: Combining strings together. Example:
string greeting = "Hello" + " " + "World";
If-Then Statements:
- Conditional Statement: A block of code executed based on a condition. Example:pythonCopy code
if (age >= 18) { // You're an adult }
- Condition: A statement that’s either true or false. Example:
temperature > 30
- Comparison Operators: Used to compare values. Example:
if (score >= 90)
- Logical Operators: Combine conditions. Example:
if (temperature > 30 && isSunny)
- Else Statement: Alternative code when the condition is false. Example:pythonCopy code
if (temperature > 30) { // It's hot } else { // It's not hot }
Loops:
- Loop: Repeating a task multiple times. Example: Print numbers from 1 to 5.
- For Loop: Repeats code for a specified number of times. Example:pythonCopy code
for (int i = 1; i <= 5; i++) { // Print i }
- While Loop: Repeats code while a condition is true. Example:pythonCopy code
int count = 1; while (count <= 5) { // Print count count++; }
- Infinite Loop: A loop that never stops. Example:pythonCopy code
while (true) { // Keep going forever }
- Break Statement: Exits a loop prematurely. Example:pythonCopy code
for (int i = 1; i <= 10; i++) { if (i == 5) { break; // Stop looping when i is 5 } }
- Continue Statement: Skips the rest of the current iteration and moves to the next. Example:pythonCopy code
for (int i = 1; i <= 5; i++) { if (i == 3) { continue; // Skip printing 3 } // Print i }
Functions:
- Function: A named block of code that performs a specific task. Example:pythonCopy code
void sayHello() { cout << "Hello, world!" << endl; }
- Parameter: A value passed to a function. Example:pythonCopy code
void greetUser(string name) { cout << "Hello, " << name << "!" << endl; }
- Return Value: The result a function gives back after its execution. Example:pythonCopy code
int addNumbers(int a, int b) { return a + b; }
Arrays:
- Array: A collection of values stored in a single variable. Example:pythonCopy code
int numbers[5] = {1, 2, 3, 4, 5};
- Index: A position of an element in an array. Example: Accessing
numbers[2]
gives you3
.
Comments:
- Comment: Notes in the code for human understanding, ignored by the computer. Example:pythonCopy code
// This is a single-line comment /* This is a multi-line comment */
User Input:
- Input: Data entered by the user during program execution. Example:pythonCopy code
int age; cin >> age; // Input age from user
Strings and Characters:
- Character: A single letter, number, symbol, or space. Example:
'A'
,'3'
,'!'
- String Length: Number of characters in a string. Example:pythonCopy code
string greeting = "Hello"; int length = greeting.length(); // length is 5
Logical Conditions:
- Nested Conditions: Using conditions inside other conditions. Example:pythonCopy code
if (age >= 18) { if (hasID) { // Allow entry } else { // Need ID } } else { // Too young }
Iterations with Loops:
- Nested Loops: Using loops inside other loops. Example:pythonCopy code
for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { // Print i and j } }
Arrays and Loops:
- Accessing Array Elements: Using a loop to access all elements in an array. Example:pythonCopy code
int numbers[5] = {1, 2, 3, 4, 5}; for (int i = 0; i < 5; i++) { // Print numbers[i] }
Error Handling:
- Syntax Error: Mistakes in the code structure that prevent execution.
- Runtime Error: Errors that occur during program execution.
- Logical Error: Code that runs but doesn’t produce the expected result.
Scope:
- Scope: The area where a variable or function is accessible. Example:pythonCopy code
int globalVar = 10; // Global scope void myFunction() { int localVar = 5; // Local scope }
Constants:
- Constant: A value that can’t be changed after declaration. Example:pythonCopy code
const float pi = 3.14159;
Type Conversion:
- Implicit Conversion: Automatic conversion between compatible data types.
- Explicit Conversion (Casting): Manually converting between data types. Example:pythonCopy code
float price = 19.99; int roundedPrice = (int)price;