GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-May-2009, 09:46
khushal_kkk's Avatar
khushal_kkk khushal_kkk is offline
Awaiting Email Confirmation
 
Join Date: Mar 2008
Posts: 50
khushal_kkk is an unknown quantity at this point

Declaration of an array at runtime ?


hello is it possible to declare an array at runtime here is my code below in which i tried to declare an array at run time please find out the errors and correct them as soon as possible .. REGARDS


CPP / C++ / C Code:

int a ;
int Data[a];

cout<<"Enter Array Size :";
cin>>a;
cout<<"Enter Data in Array: ";
for(int i=0;i<=a;i++)
{

cin>>Data[i];
}
for(int j=0;j<=a;j++)
cout<<Data[j];
}

  #2  
Old 21-May-2009, 09:53
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 757
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Declaration of an array at runtime ?


CPP / C++ / C Code:
int a;
int* Data = NULL;

cout<<"Enter Array Size :";
cin>>a;

// At runtime, it must be done with the "new" operator
Data = new int[a];

// ....


// When done we must "delete" Data because we used "new" to create it
delete[] Data;
  #3  
Old 21-May-2009, 10:03
khushal_kkk's Avatar
khushal_kkk khushal_kkk is offline
Awaiting Email Confirmation
 
Join Date: Mar 2008
Posts: 50
khushal_kkk is an unknown quantity at this point

Re: Declaration of an array at runtime ?


thanx alot for helping me ....
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 66 16-Jan-2010 11:53
where is the problem and can you fix it (php) oggie MySQL / PHP Forum 8 14-Apr-2008 16:08
Getting a line error in register oggie MySQL / PHP Forum 5 13-Apr-2008 17:16
What is an array? Howard_L C Programming Language 3 05-Oct-2007 06:11
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 20:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:08.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.