دنبال کننده ها

۱۳۹۶ آبان ۱۱, پنجشنبه

c++ Pointer array of structure

[ad_1]



#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
struct telephone

char name[10];
char tno[9];
;


void main()



telephone a[5];
clrscr();
telephone* p ;
p=a;
strcpy(a[0].name,"Aditya");// initialing the array
strcpy(a[1].name,"Harsh ");
strcpy(a[2].name,"Kartik");
strcpy(a[3].name,"Ayush ");
strcpy(a[4].name,"Shrey ");
strcpy(a[0].tno ,"873629595" );
strcpy(a[1].tno ,"834683565" );
strcpy(a[2].tno ,"474835595" );
strcpy(a[3].tno ,"143362465" );
strcpy(a[4].tno ,"532453665" );

for(int i=0;i<5;i++)

puts((p+i)->name);cout<< " "; //command for output
puts((p+i)->tno );cout<<endl;

getch();



/* in this code while taking output i am not getting output of names
i only get output for (p+0)->name and not for anything else
but if i don't initialize the telephone number then i get output of names
*/




[ad_2]

لینک منبع