Jul 17, 2024
#include <iostream>
using namespace std;
int main() {
// Code
return 0;
}
#include <iostream>
for I/O operationscout << "Striver" << endl;
``
std::
for using I/O functions like cout
and cin
std::
each time, use using namespace std;
int
, long
, long long
float
, double
char
(single character)string
(sequence of characters)int x;
cin >> x;
cout << x << endl;
``
#include <bits/stdc++.h>
– Includes all standard librariesif (condition) {
// code
} else if (condition) {
// code
} else {
// code
}
int age;
cin >> age;
if (age >= 18) {
cout << "You are an adult";
} else {
cout << "You are not an adult";
}
switch(variable) {
case 1: // code
break;
case 2: // code
break;
...
default: // code
}
int arr[5];
for (int i = 0; i < 5; i++) {
cin >> arr[i];
}
for (int i = 0; i < 5; i++) {
cout << arr[i] << " ";
}
int arr[3][5];
// 3 rows, 5 columns
string s = "Striver";
cout << s[0] << endl; // Prints 'S'
s[0] = 'Z';
cout << s[0] << endl; // Prints 'Z'
for (int i = 0; i < n; i++) {
// code
}
for (int i = 1; i <= 10; i++) {
cout << i << endl;
}
int i = 0;
while (i < n) {
// code
i++;
}
int i = 0;
do {
// code
i++;
} while(i < n);
return_type function_name(parameters) {
// Code
return value;
}
void printName() {
cout << "Striver" << endl;
}
void printName(string name) {
cout << name << endl;
}
int add(int num1, int num2) {
return num1 + num2;
}
void changeValue(int a) {
a = 5; // Affect local 'a' only
}
void changeValue(int &a) {
a = 5; // Affect original variable
}
void modifyArray(int arr[], int size) {
arr[0] = 10; // Original array modified
}