Variables In Cpp Hindi :- C++ Variable jab create kiya jata hai tab interpreter dauvara value ko store karne ke liye memory location assign ki jati hai .
Variables In C++ Hindi
Contents
Variable par koi bhi data type ki value store ki ja sakti hai | Example : Number , String, int,float , etc.
Assigning Value To Variable in c++
Jab Ham Variable Create Karte hai C++ me to sabse pahle hame ye batana hota hai ki ham kis type ki value assign karni hai |
For Example
#include <iostream> using namespace std; int main() { int var = 10; cout <<"The Value is "<<var; return 0; }
Output :
The Value is 10
Changing Variable’s Value in c++
C++ me variable ki value change ya re-assign ki ja sakti hai |
Example :
#include <iostream> using namespace std; int main() { int var = 10; cout <<"The First value is "<<var; cout <<"\n"; var = 20; // changing value cout <<"The Changing value is "<<var; return 0; }
Output :
The Changing value is 10 The Changing value is 20
Assigning Single Value to Multiple Variables
C++ me ek hi value ek se jyada variables par assign ki ja sakti hai |
For Example :
#include <iostream> using namespace std; int main() { double x, y, z; x = y = z = 50; cout << " " << x << " " << y << " " << z; return 0; }
Output :
50 50 50
Variables Concatenation in C++
C++ me ek hi data types ke variables concatenate kiye ja sakte hai |
See Example :
#include <bits/stdc++.h> using namespace std; int main() { string init("Master"); string add(" Programing"); // Appending the string. init = init + add; cout << init << endl; return 0; }
Output :
Master Programing
Types of Variables In C++ Hindi
Variables In C++ Hindi – C++ Programming me variable ke two type hote hai|
- 1 . Local Variables
- 2 . Global Variables
1 . Local Variables
Local Variables, functions ke under hote hai| unki visibility sirf function ke under hoti hai, jab wo function ke bahar aate hai tab destroy ho jate hai|
For Example :
#include <iostream> using namespace std; int multiply(int a, int b){ return a * b; } int main() { int x = 3, y = 5; int z; z = multiply( x, y ); cout << z << endl; return 0; }
Output :
15
2. Global Variables
Global Variables , function ke bahar hote hai | unki visibility function ke under or bahar hoti hai| unka scope pure program par hota hai |
Source Code :
#include <iostream> using namespace std; int g; int main(){ int a = 4; g = a * 2; cout << g << endl; return 0; }
Output:
8
Example local or global ye dono variables declared kiye gye hai | function ke bahar ka variable local hai | or under ka variable local hai | global variable ka scope function ke under or bahar hota hai lekin function ke under alag se variable declaration hone ke karan func() call karte hi variable ki value change ho jati hai|
Variables In Cpp Hindi
Also Read This Post
Hello sir aap se contact karna he [email protected] please help