📘

Programming Basics and Preparation Guide by Striver

Jun 22, 2024

Programming Basics and Preparation Guide by Striver

Introduction

  • Welcome to the channel (Striver in the programming community).
  • Connect on LinkedIn, Twitter, Instagram, and Telegram.
  • Full-fledged interview preparation website: Strivers’ SDE sheet.

Resources Provided

  • Strivers SDE Sheet: 191 problems covering all DS algo concepts for interview prep.
  • Strivers A to Z DSA Course: 455 steps with problem links and videos for beginners and intermediates.
  • Coding Ninjas: Mentioned for other programming courses.

C++ Programming Basics

Skeleton of C++ Code

  • Starts with #include directives (e.g., #include <iostream>).
  • Use namespaces to avoid repetition (using namespace std;).
  • int main() { } is the entry point of the program.

Input and Output

  • cin for input, cout for output.
  • Use std::cin and std::cout if not using namespace.
  • Use or std::endl for new lines.
  • Prefer for faster execution.

Data Types

  • Integer Types: int, long, long long.
  • Floating Point: float, double.
  • Character and String: char, string.
  • Input/Output for String: cin for word inputs, getline(cin, str) for full line inputs.

Control Statements

If-Else Statements

  • Syntax: if (condition) { } else { }.
  • Use logical operators: && (AND), || (OR).
  • Example: Determine adulthood by age.

Nested If-Else

  • Inner if-else inside outer if-else for multiple conditions.
  • Example: Print grade based on marks.

Switch Statements

  • Syntax: switch (variable) { case value1: //code; break; ... default: //code; }.
  • Use break to prevent fall-through.
  • Example: Print day of the week based on number.

Arrays and Strings

One-Dimensional Arrays

  • Declaration: int arr[5];.
  • Access elements using index: arr[0], arr[1], ....

Two-Dimensional Arrays

  • Declaration: int arr2D[3][5];.
  • Access elements using indices: arr2D[0][0], arr2D[1][4], ....

String Manipulation

  • Strings as arrays of characters.
  • Access elements using indices: str[0], str[1], ....
  • Use .length() or .size() for length of string.

Loops

For Loops

  • Syntax: for (initialization; condition; increment) { }.
  • Example: Print a name multiple times.

While Loops

  • Syntax: while (condition) { }.

Do-While Loops

  • Syntax: do { } while (condition);.
  • Ensures the loop runs at least once.

Functions

Void Functions

  • Syntax: void functionName() { }.
  • Doesn't return a value.
  • Can be parameterized or non-parameterized.

Return Functions

  • Syntax: returnType functionName(parameters) { return value; }.

Pass by Value vs. Pass by Reference

  • Pass by Value: Passes a copy, original remains unchanged.
  • Pass by Reference: Use & to pass the original, changes affect original.

Additional Topics

Built-in Functions

  • Example: min(), max() in <algorithm>.

Example Problems and Solutions

  • Write a program that prints if a person is an adult based on age.
  • Write a program that calculates sum of two numbers using functions.

Conclusion

  • Stay tuned for more educational videos on data structures and algorithms.
  • Follow Striver on social media for updates.