C++ Pointers

C++ Pointers In Hindi – Pointers In Hindi

C++

C++ Pointers In HindiPointers In HindiPointer Vo Variables Hote Hai Jo Dusre Variables ka Address ko store karte hai | Jesa ki aapko pta hai ki har variable ka memory me ek unique address hota hai |

Ye address hexadecimal form mei Hota hai | Isliye Is address ko Aap Kisi Bhi normal variable me store Nhi Kar Sakte hai |

C++ Pointers In Hindi

Kisi Bhi Variable ke address ko store Karwane Ke Liye Aap pointer variable create Karte hai |

for example, Aap Maan Lijiye Aapne Ek variable create Kiya hai | is variable ka name Student_Age hai or Aapne Isme 30 value assign Karwayi hai | to is variable ki memory mei location (address) 50F hai | ab Yadi Aap Chahe to Is address ko Ek pointer variable Me store Karva Sakte hai |

C++ Declaring Pointers In Hindi

C++ Pointers ko declare Karne Ke Liye Sabse Pahle Data Type Declare Karte hai | Aesa Isliye Kiya Jata hai Kyoki int type ka pointer variable Keval int type ke variables ka hi address store Kar Sakta hai |

Syntax:

Data_type *pointer_variable;

// Example
int    *ip;    // pointer to an integer
double *dp;    // pointer to a double
float  *fp;    // pointer to a float
char   *ch     // pointer to character
  • Data_type:- Int, Float, String, etc.
  • Pointer_Variable:- Aap Asterisk(*) operator ko pointers declare Karne Ke Liye Istemal Karte hai And Iske bad pointer variable ka name declare Karte hai

C++ Initializing Pointers In Hindi

C++ pointers initialize Karne ke liye sabse pahle aap pointer variable ko Likhte hai | ( Initialization part mei pointer variable ko Bina asterisk operator (*) ke Likha Jata hai |

pntr_variable = &variable_name;

Iske bad aap ampersand operator yani address(&) (ise address of operator bhi kaha jata hai ) define karte hai | is operator ke bad aap bina koi space diye variable ka name likhte hai

Advantages of Pointer in Hindi  

  1. Pointers ki help se aap dynamically memory allocate kar sakte hai|
  2. Pointers ki help se aap data structures ( linked-list, stack, queue) create kar sakte hai|
  3. Pointers ki help se aap Function se ek se jyada values return Kar sakte hai |
  4. pointers ki help se argument passing ke douran aap variable ki copy ke badle original variable par Kam kar sakte hai|
  5. pointers istemal karne se program ka execution time kam ho jata hai |
  6. Pointers ke duvara large data ko search or sort Karna bahut Aashan Hota hai|

Example:

C++ Mai Address Ko Print Karne Ke Liye ( & ) Ka Istemal Hota Hain |

#include <iostream>

using namespace std;
int main () {
   int  var1 = 10;
   int* var2 = &var1;
   
   cout << "Value of var1 variable: ";
   cout << var1 << endl;

   cout << "Address of var1 variable: ";
   cout << var2 << endl;

   return 0;
}

Output:

Value of var1 variable: 10                                                                                                    
Address of var1 variable: 0x7ffe1be24194 

C++ Pointers to Structure in Hindi

Structure variables ke pointers bhi create kiye ja sakte hai | ye usi tarah create kiye jate hai jese ki aap kisi normal variable ke pointers create karte hai |

Example 2:

#include <iostream>
using namespace std;

struct Distance
{
    int feet;
    float inch;
};

int main()
{
    Distance *ptr, d;

    ptr = &d;
    
    cout << "Enter feet: ";
    cin >> (*ptr).feet;
    cout << "Enter inch: ";
    cin >> (*ptr).inch;
 
    cout << "Displaying information." << endl;
    cout << "Distance = " << (*ptr).feet << " feet " << (*ptr).inch << " inches";

    return 0;
}

Output:

Enter feet: 4
Enter inch: 3.5
Displaying information.
Distance = 4 feet 3.5 inches

C++ Pointers And String In Hindi

Pointers Ko Ham String Mai Bhi Istemal Kar Sakte Hain.

Example:

#include <iostream>
using namespace std;

int main(){
	char name[ ]= "Danish";
  	char *p;
  	p = name;     /* for string, only this declaration will store its base address */
  	while( *p != '\0')
  	{
    	cout << *p;
    	p++;
  	}
	return 0;
}

Output:

Danish

C++ Pointers and Arrays in Hindi

Arrays ko pointers mei kaise Istemal karte hai | ye program ham simple tarah se dekhte hai |

Example:

// C++ Program to insert and display data entered by using pointer notation.

#include <iostream>
using namespace std;

int main() {
    float arr[5];
    
   // Insert data using pointer notation
    cout << "Enter 5 numbers: ";
    for (int i = 0; i < 5; ++i) {

        // store input number in arr[i]
        cin >> *(arr + i) ;

    }

    // Display data using pointer notation
    cout << "Displaying data: " << endl;
    for (int i = 0; i < 5; ++i) {

        // display value of arr[i]
        cout << *(arr + i) << endl ;

    }

    return 0;
}

Output:

Enter 5 numbers: 10 20 30 50 40                                                                                                                   
Displaying data:                                                                                                              
10                                                                                                                            
20                                                                                                                            
30                                                                                                                            
50                                                                                                                            
40 

Yadi Aapne  HTML Full Course  And CSS Full Course And Python Full Course And PHP Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

Leave a Reply

Your email address will not be published. Required fields are marked *