पॉइंटर्स की सरणी (स्ट्रिंग्स के लिए)
पॉइंटर्स का ऐरे एक ऐरे है जिसके तत्व स्ट्रिंग के आधार पते पर पॉइंटर्स हैं।
इसे निम्नानुसार घोषित और आरंभ किया गया है -
char *a[3 ] = {"one", "two", "three"};
//Here, a[0] is a ptr to the base add of the string "one"
//a[1] is a ptr to the base add of the string "two"
//a[2] is a ptr to the base add of the string "three" फायदे
-
वर्णों की द्वि-आयामी सरणी को अनलिंक करें। इन (स्ट्रिंग्स की सरणी), पॉइंटर्स टू स्ट्रिंग्स की सरणी में स्टोरेज के लिए कोई निश्चित मेमोरी साइज नहीं है।
-
स्ट्रिंग्स जितनी आवश्यकता हो उतने बाइट्स लेती हैं, इसलिए जगह की बर्बादी नहीं होती है।
उदाहरण 1
#include<stdio.h>
main (){
char *a[5] = {“one”, “two”, “three”, “four”, “five”};//declaring array of pointers to
string at compile time
int i;
printf ( “The strings are:”)
for (i=0; i<5; i++)
printf (“%s”, a[i]); //printing array of strings
getch ();
} आउटपुट
The strings are: one two three four five
उदाहरण 2
स्ट्रिंग्स के लिए पॉइंटर्स की सरणी पर एक और उदाहरण पर विचार करें -
#include <stdio.h>
#include <String.h>
int main(){
//initializing the pointer string array
char *students[]={"bhanu","ramu","hari","pinky",};
int i,j,a;
printf("The names of students are:\n");
for(i=0 ;i<4 ;i++ )
printf("%s\n",students[i]);
return 0;
} आउटपुट
The names of students are: bhanu ramu hari pinky