Static vs Dynamic Typing - C++ vs Python
Roman Urdu Script
Roman Urdu Script (Answer for Sir ya Presentation)
Sir, Python mein hum `x = 10` likhtay hain kyunki wo dynamic typing use karta hai yani variable ka type run
time pe decide hota hai. Lekin C++ mein humein `int x = 10;` likhna padta hai kyunki wo static typing use
karta hai.
Static typing ka faida yeh hai ke agar koi galti ho, jaise galat type assign kar dein, to C++ ka compiler usay
program chalne se pehle hi pakar leta hai. Python mein aisi galti sirf tab pata chalti hai jab wo line actually
run hoti hai.
Is wajah se C++ zyada safe aur fast hota hai thoda strict hai, lekin long-term mein better hai.
C++ Code Example
C++ Code (Static Typing Example)
#include <iostream>
using namespace std;
int main() {
int x = 10;
// int x = "hello"; // Try uncommenting this to see the type error
Static vs Dynamic Typing - C++ vs Python
cout << "x = " << x << endl;
return 0;
Python Code Example
Python Code (Dynamic Typing Example)
x = 10
# x = "hello" + 5 # Uncomment to see runtime error
print("x =", x)