C++ Codes - Basic to Advanced 💻
الذهاب إلى القناة على Telegram
💡 Daily C++ Codes with Output & Logic Any queries, message 👉 @sai7981 🤖 Get instant code explanations: @cpp_codes_bot 🔗 Join now: @cpp_code_snippets #cpp #dsa #coding #programming
إظهار المزيد3 188
المشتركون
لا توجد بيانات24 ساعات
+357 أيام
+12030 أيام
أرشيف المشاركات
Smart Pointers: std::unique_ptr
cpp
#include <iostream>
#include <memory>
class Resource {
public:
Resource() { std::cout << "Resource acquired.\n"; }
~Resource() { std::cout << "Resource released.\n"; }
void do_something() { std::cout << "Resource doing something.\n"; }
};
int main() {
std::unique_ptr<Resource> ptr1 = std::make_unique<Resource>();
ptr1->do_something();
std::unique_ptr<Resource> ptr2;
ptr2 = std::move(ptr1);
if (ptr1 == nullptr) {
std::cout << "ptr1 is now null.\n";
}
if (ptr2) {
ptr2->do_something();
}
return 0;
}
Hello World in C
c
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Pointers and Dynamic Memory Allocation in C++
#include <iostream>
int main() {
int *ptr;
ptr = new int;
*ptr = 10;
std::cout << "Value at ptr: " << *ptr << std::endl;
delete ptr;
ptr = nullptr;
return 0;
}C++: Reading Integers and Calculating Their Sum
#include <iostream>
int main() {
int num1, num2, sum;
std::cin >> num1 >> num2;
sum = num1 + num2;
std::cout << sum << std::endl;
return 0;
}❌Make sure you have started the bot to receive explainations
👉@cpp_codes_bot
Bot still under development, might make some mistakes
⚠️Use the channel only for your revision/for building problem solving skills if you need courses,
Join 👉 https://t.me/skills_stream_free_courses
Pointers and Memory Allocation in C
#include <stdio.h>
#include <stdlib.h>
int main() {
int *ptr;
int n = 5;
ptr = (int*) malloc(n * sizeof(int));
if (ptr == NULL) {
printf("Memory allocation failed!\n");
return 1;
}
for (int i = 0; i < n; i++) {
ptr[i] = i * 2;
}
for (int i = 0; i < n; i++) {
printf("ptr[%d] = %d\n", i, ptr[i]);
}
free(ptr);
ptr = NULL;
return 0;
}🔥🔥Dove Advanced Sensitive Care Bodywash| Ceramide Nutrient Cream| 250 ml
🎁 Deal Price : ₹150
Buy Here : https://amzn-to.co/POGAgX
🔥🔥SKYBAGS BRAT 21.65 L Backpack
🎁 Deal Price : ₹399
Buy Here : https://fkrt.co/uBdw4C
🔥🔥Santoor Fresh Skin Aloe Vera & Lime Bathing Soap with Nourishing & Anti-Aging Properties | 125g, Pack of 4
🎁 Deal Price : ₹135
Buy Here : https://amzn-to.co/62oLma
⚡️⚡️Apply ₹7.5 Coupon
🔥🔥boAt Aavante Bar 490 10W Signature Sound, Dual Full-Range Drivers,7 HRS Battery
🎁 Deal Price : ₹999
Buy Here : https://amzn-to.co/53Okjb
🔥🔥Pigeon 16246 Electric Kettle
🎁 Deal Price : ₹499
Buy Here : https://fkrt.co/05vjZ6
🔥🔥Yardley London Navy- Body Spray for Men- 150ml
🎁 Deal Price : ₹109
Buy Here : https://amzn-to.co/qhgSG5
🔥🔥JioBharat K1 Karbonn 4G Keypad Phone with JioTV, JioHotstar, JioSoundPay
🎁 Deal Price : ₹699
Buy Here : https://amzn-to.co/CkZMiw
🔥🔥vivo T4 Lite 5G Charger in the Box (Prism Blue, 128 G😎
🎁 Deal Price : ₹9,499
Buy Here : https://fkrt.co/eUcSPE
💥 Bank Offer : ₹500 Instant Discount on HDFC, SBI Credit Cards Txn
