কম্পিউটার

পয়েন্টারগুলিতে উদাহরণ প্রদর্শন করে একটি সি প্রোগ্রাম লিখুন


একটি পয়েন্টার একটি ভেরিয়েবল যা অন্য ভেরিয়েবলের ঠিকানা সংরক্ষণ করে।

পয়েন্টারের বৈশিষ্ট্যগুলি

  • পয়েন্টার মেমরি স্পেস সংরক্ষণ করে।

  • মেমরি অবস্থানে সরাসরি অ্যাক্সেসের কারণে একটি পয়েন্টার কার্যকর করার সময় দ্রুততর হয়৷

  • পয়েন্টারগুলির সাহায্যে, মেমরিটি দক্ষতার সাথে অ্যাক্সেস করা হয়, অর্থাত্, মেমরি বরাদ্দ করা হয় এবং গতিশীলভাবে ডিললোকেট করা হয়৷

  • ডেটা স্ট্রাকচারের সাথে পয়েন্টার ব্যবহার করা হয়।

পয়েন্টার ঘোষণা করা হচ্ছে

int *p;

এর মানে 'p' হল একটি পয়েন্টার ভেরিয়েবল যা অন্য পূর্ণসংখ্যা ভেরিয়েবলের ঠিকানা ধারণ করে।

পয়েন্টারের সূচনা

ঠিকানা অপারেটর (&) একটি পয়েন্টার ভেরিয়েবল শুরু করতে ব্যবহৃত হয়।

উদাহরণস্বরূপ,

int qty = 175;
int *p;
p= &qty;

পয়েন্টারগুলিতে উদাহরণ প্রদর্শন করে একটি সি প্রোগ্রাম লিখুন

পয়েন্টারের মাধ্যমে একটি ভেরিয়েবল অ্যাক্সেস করা

ভেরিয়েবলের মান অ্যাক্সেস করতে, ইনডাইরেকশন অপারেটর (*) ব্যবহার করা হয়।

প্রোগ্রাম

#include<stdio.h>
void main(){
   //Declaring variables and pointer//
   int a=2;
   int *p;
   //Declaring relation between variable and pointer//
   p=&a;
   //Printing required example statements//
   printf("Size of the integer is %d\n",sizeof (int));//4//
   printf("Address of %d is %d\n",a,p);//Address value//
   printf("Value of %d is %d\n",a,*p);//2//
   printf("Value of next address location of %d is %d\n",a,*(p+1));//Garbage value from (p+1) address//
   printf("Address of next address location of %d is %d\n",a,(p+1));//Address value +4//
   //Typecasting the pointer//
   //Initializing and declaring character data type//
   //a=2 = 00000000 00000000 00000000 00000010//
   char *p0;
   p0=(char*)p;
   //Printing required statements//
   printf("Size of the character is %d\n",sizeof(char));//1//
   printf("Address of %d is %d\n",a,p0);//Address Value(p)//
   printf("Value of %d is %d\n",a,*p0);//First byte of value a - 2//
   printf("Value of next address location of %d is %d\n",a,*(p0+1));//Second byte of value a - 0//
   printf("Address of next address location of %d is %d\n",a,(p0+1));//Address value(p)+1//
}

আউটপুট

Size of the integer is 4
Address of 2 is 6422028
Value of 2 is 2
Value of next address location of 2 is 10818512
Address of next address location of 2 is 6422032
Size of the character is 1
Address of 2 is 6422028
Value of 2 is 2
Value of next address location of 2 is 0
Address of next address location of 2 is 6422029

  1. পয়েন্টারগুলিতে উদাহরণ প্রদর্শন করে একটি সি প্রোগ্রাম লিখুন

  2. সি প্রোগ্রাম স্ট্রিং এবং তাদের ঠিকানা পয়েন্টার অ্যারে মুদ্রণ

  3. রিভার্স অ্যারে করার জন্য একটি সি প্রোগ্রাম লিখুন

  4. সি প্রোগ্রাম পিজিএম ফরম্যাটে একটি ছবি লিখতে